How to populate a box as clicking on map with JavaScript? -
hi i'm trying stuff on google maps api javascript , i've problem populating text box. have map , geocoding box . can directly input coordinates box , makes reverse geocoding point. want right click . want box filled right click on map. couldn't it.
here code use ;
<div id="floating-panel"> <input id="latlng" type="text" value="40.714224,-73.961452"> <input id="submit" type="button" value="reverse geocode"> </div> <div id="map"></div> <script> function initmap() { var map = new google.maps.map(document.getelementbyid('map'), { zoom: 8, center: {lat: 40.731, lng: -73.997} }); google.maps.event.addlistener(map, "rightclick", function(event) { var lat = event.latlng.lat(); var lng = event.latlng.lng(); // populate yor box/field lat, lng alert("enlem=" + lat + "; boylam=" + lng); floating-panel="latlng" type="text" value=lat+","+lng
hopefully helps. listener looked fine way populate input box bit unclear
"floating-panel="latlng" type="text" value=lat+","+lng"
google.maps.event.addlistener(map, "rightclick", function(event) { var lat = event.latlng.lat(); var lng = event.latlng.lng(); document.getelementbyid("latlng").value = lat.tofixed(5)+', '+lng.tofixed(5); });
Comments
Post a Comment