Retrieve Google Maps address reporting Long and Lat

3

I have the latitude and longitude of a location in Google Maps, obtained from a marker and its own function, I would like to know if anyone has an idea or function that returns the complete address of the location based on these two parameters.

    
asked by anonymous 10.07.2015 / 19:13

2 answers

4

Use the following URL to get a JSON with the address:

http://maps.googleapis.com/maps/api/geocode/json?latlng=44.4647452,7.3553838&sensor=true

In this case, the latitude is: 44.4647452 and the longitude: 7.3553838

An example, provided by the author of the peg is shown below:

var latlng = lat + "," +lng; 
var url = "maps.googleapis.com/maps/api/geocode/json?latlng=" + latlng + "&sensor=true"; 
$.getJSON(url, function (data) { 
    for(var i=0;i<data.results.length;i++) 
    { 
        var adress = data.results[i].formatted_address; 
        //alert(adress); 
        document.getElementById('endereco_saida_maps').value = adress; 
        endereco_campo.value = adress; 
    } 
});
    
10.07.2015 / 19:37
1

Another idea:

function cityByLatLng(latitude, longitude) {
    var geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(latitude, longitude);
    geocoder.geocode({'location': latlng}, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            if (results[0]) {
                document.getElementById('seu elemento').value = results[0].formatted_address;
            } else {
                window.alert('No results found');
            }
        } else {
            window.alert('Geocoder failed due to: ' + status);
        }
    });
}
    
24.07.2015 / 20:59