javascript - Google Version 3 Maps Geocoder, Get Coordinates of marker layer when clicking or dragging marker -


i have made google version 3 geocoder , want able pick coordinates of marker when dragged or clicked. below code:

<!doctype html> <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no"/> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title>google maps javascript api v3 example: geocoding simple</title> <link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" /> <script src="http://maps.google.com/maps/api/js?v=3.5&amp;sensor=false"></script> <script type="text/javascript"> var geocoder; var map; function initialize() { geocoder = new google.maps.geocoder(); var latlng = new google.maps.latlng(-34.397, 150.644); var myoptions = {   zoom: 8,   center: latlng,   maptypeid: google.maps.maptypeid.roadmap } map = new google.maps.map(document.getelementbyid("map_canvas"), myoptions); }   function codeaddress() { var address = document.getelementbyid("address").value; geocoder.geocode( { 'address': address}, function(results, status) {   if (status == google.maps.geocoderstatus.ok) {     map.setcenter(results[0].geometry.location);     var marker = new google.maps.marker({         map: map,         draggable: true,         position: results[0].geometry.location      });   } else {     alert("geocode not successful following reason: " + status);   } }); } </script>  <style type="text/css"> #controls { position: absolute; bottom: 1em; left: 100px; width: 400px; z-index: 20000; padding: 0 0.5em 0.5em 0.5em; }  html, body, #map_canvas {             margin: 0;             width: 100%;             height: 100%;         } </style> </head> <body onload="initialize()"> <div id="controls"> <input id="address" type="textbox" value="sydney, nsw">  <input type="button" value="geocode" onclick="codeaddress()"> </div> <div id="map_canvas"></div> </body> </html> 

i have tried use following code not seem work.

       // javascript//        google.maps.event.addlistener(marker, 'dragend', function(evt){        document.getelementbyid('current').innerhtml = '<p>marker dropped: current lat: ' + evt.latlng.lat().tofixed(3) + ' current lng: ' + evt.latlng.lng().tofixed(3) + '</p>';        });         google.maps.event.addlistener(marker, 'dragstart', function(evt){        document.getelementbyid('current').innerhtml = '<p>currently dragging marker...</p>';        });   map.setcenter(marker.position);  marker.setmap(map);   //html//  <div id='map_canvas'></div>  <div id="current">nothing yet...</div> 

that code works fine if put in correct place:

http://www.geocodezip.com/blakeloizides_geocode.html

(inside callback routine, marker local it)


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -