Created
November 13, 2010 12:06
-
-
Save makestory/675272 to your computer and use it in GitHub Desktop.
a function used to locate lat/lng by address name (google maps api v3)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function initialize() { | |
map = new google.maps.Map(document.getElementById("your_map_canvas")); | |
// example => geocoding('China Beijing') | |
function geocoding(address){ | |
geocoder.geocode( {'address': address }, function(results, status) { | |
if(status == google.maps.GeocoderStatus.OK){ | |
$.map(results, function(item) { | |
map.setCenter(new google.maps.LatLng(item.geometry.location.lat(),item.geometry.location.lng())); | |
map.setZoom(item.address_components.length * 2 + 3); | |
marker.setPosition(map.getCenter()) | |
}) | |
} | |
else{ | |
alert('Can not find' + address); | |
}; | |
}); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment