Skip to content

Instantly share code, notes, and snippets.

@makestory
Created November 13, 2010 12:06
Show Gist options
  • Save makestory/675272 to your computer and use it in GitHub Desktop.
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)
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