Skip to content

Instantly share code, notes, and snippets.

@ricardodantas
Created March 11, 2014 18:35
Show Gist options
  • Save ricardodantas/9492153 to your computer and use it in GitHub Desktop.
Save ricardodantas/9492153 to your computer and use it in GitHub Desktop.
Google Maps API - Pegar a latitude e longitude de um endereço
window.geocoder = new google.maps.ClientGeocoder();
geocoder.getLocations('rua xyz, sp', function(result){
var placemark = result.Placemark[0]; // Only use first result
var accuracy = placemark.AddressDetails.Accuracy;
var zoomLevel = 1;
var lon = placemark.Point.coordinates[0];
var lat = placemark.Point.coordinates[1];
gmap.setCenter(new google.maps.LatLng(lat, lon), zoomLevel);
});
//-----------------------
// ou
//-----------------------
// Apenas retorna latitude e longitude
function GetLocation(address) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var latitude = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng();
alert("Latitude: " + latitude + "\nLongitude: " + longitude);
} else {
alert("Request failed.")
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment