javascript - Working with google.maps.Geocoder(). Asynchronous callback -
i've been trying geocode address latlng coordinates, i'm having lot of difficulty doing so. know geocode() asynchronous function, , have been toying callbacks no avail. i've been looking @ other posts 1 (how homecoming value callback function), i'm having difficulty understanding concept. if can show me how callback function, much appreciated. lot of headache on one. able callback alert() gives right latlng, not set position parameter. sorry couldn't figure out illustration cited earlier. pretty new language. references can point me to understand concept appreciated well. thanks!
var location; var image; var map; var geocoder; var address; function initialize() { var mapoptions = { center: new google.maps.latlng(42.763146, -73.3776), zoom: 6, maptypeid: google.maps.maptypeid.roadmap }; var map = new google.maps.map(document.getelementbyid("map_canvas"), mapoptions); var cloudlayer = new google.maps.weather.cloudlayer(); cloudlayer.setmap(map); addressset(function(address) { console.log(address); // tried set location = address;, location = new google.maps.latlng(address); // neither works }); addmtstomap(location, map, new google.maps.markerimage("img/mts/skier.png", null, null, null, new google.maps.size(50,50))); } function addmtstomap(location, map, image) { var marker = new google.maps.marker({ position: location, map: map, icon: image }); var infowindow = new google.maps.infowindow({content: "<h1>powder!!!</h1>"}); google.maps.event.addlistener(marker, "click", function() { infowindow.open(map, marker); }); } function addressset(callback) { geocoder = new google.maps.geocoder(); geocoder.geocode({address: "killington+vt"}, function(results, status) { if (status == google.maps.geocoderstatus.ok) { address = results[0].geometry.location; callback(address); } }); }
sorry all. couldn't believe found after messing long. declared var map 1 time again in initialize, made addressset() function pull wrong global map variable. deleting var made work.
javascript asynchronous callback google-geocoder
No comments:
Post a Comment