javascript - Google Map geocoder get long and lat -
i trying long , lat of cities through loop.
now have done coding still due geocoder being asynchronous function not working (map not loading , markers not shown). output of geocoder trying display markers on map.
function codeaddress(address, map, callback) { geocoder.geocode( { 'address': address}, function(results, status) { if (status == google.maps.geocoderstatus.ok) { var latlng = new google.maps.latlng(results[0].geometry.location.lat().lat,results[0].geometry.location.lng()); var markerobj = new markerwithlabel({ position: latlng, title:name, labelcontent: name, labelclass:'marker-labels', icon:markerimg }); markerobj.setmap(map); console.log(latlng); return callback(map, latlng); } else { console.log('geocode not successful following reason: ' + status); } }); } function initialize() { var mapoptions = { maptypeid: google.maps.maptypeid.roadmap }; map = new google.maps.map(document.getelementbyid('googlemap'),mapoptions); if ('' != markersaddress) { (var x=0; x<markersaddress.length; x++) { var address = markersaddress[x].address; var name = markersaddress[x].name; codeaddress(address, map, function(map, latlng) {}) } } } google.maps.event.adddomlistener(window, 'load', initialize);
js fiddle http://jsfiddle.net/qe9sol4o/5/
you using markerwithlabel
havent included it
include both these files in head
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true"></script>
<script src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerwithlabel/src/markerwithlabel.js"></script>
note order of these files important
Comments
Post a Comment