Google Maps Latitude Longitude does not have an address but exists in Google Maps

0

I'm using the google api http://maps.googleapis.com/maps/api/geocode/json?address where we passed the address to return to Latitude and Longitude.

The problem is: If you type for example this street address muller carioba, it will not return any results and this address comes from the postal code base. However, typing the same address on the google maps page returns it.

Does anyone know how to improve this search?

Thank you.

EDITING THE QUESTION:

I am using the search tool of the postal code, that is, searching for the zip code: 04291-020 the return is Rua Muller Carioba. Note that there are 2 letters L in the name. Placing the same address in the Google URL to search for the coordinates:

http://maps.googleapis.com/maps/api/geocode/json?address=Rua Muller Carioba, 100, Jardim da Saude Sao Paulo SP

We have the following result:

   {
   "results" : [],
   "status" : "ZERO_RESULTS"
}

Now, if we simply remove 1 of the 2 L from the name, the result comes in correctly. So my question is: How do you make this LAT / LNG search work the same as Google Maps? For in Google Maps he finds either 1L or 2L.

    
asked by anonymous 21.09.2017 / 02:15

2 answers

0

Placing as Google Map search "Rua Muller Carioba, 100, Jardim da Saude Sao Paulo SP", nothing was found. Putting the same search, without the number, found!

Yet anyway, your URL has an error: spaces!

When you perform a parameterized URL request (called Query String ), you must replace spaces with %20 or + , so that the browser understands your request.

So, if you run the query below: (already removing the number 100, since with the number 100, nor even the Google maps found)

http://maps.googleapis.com/maps/api/geocode/json?address=Rua+Muller+Carioba+Jardim+da+Saude+Sao+Paulo+SP

You will have the expected return!

    
21.09.2017 / 14:03
0

The problem with consuming this API method of google.maps is that it has a daily request limit, in which case you have to force the request recursively. That is, whenever you do this and return the error "ZERO_RESULTS , you redo the query. Clearly via Client Side

Below is an example of how you can do this in Javascript :

Note that in case of operation failure, it will set a time of 3 seconds and redo, forcing the method (native to the API ) Geocoder to fetch the address via latitude and longitude. p>

function getEndereco(lat, long, callback) {
    try {
        let geocoder = new google.maps.Geocoder;
        let LatLng = new google.maps.LatLng(lat, long)
        geocoder.geocode({ 'location': LatLng }, function (results, status) {
            let endereco = "Tente Novamente"
            if (status === 'OK') {
                if (results[1]) {
                    endereco = results[0].formatted_address
                    console.log("OK: " + endereco + " - Lat: " + lat + " - Lng: " + long);
                }
            }
            else if (status == 'ZERO_RESULTS') {
                clearTimeout(function () {
                    getEndereco1(lat, long, callback)
                })
            }
            else {
                setTimeout(function () {
                    getEndereco1(lat, long, callback)
                }, 3000)
                console.log("status: " + status);
            }
            callback(endereco);
        });
    }
    catch (err) {
        console.log("Erro na Função 'getEndereco' mensagem do erro: " + err.message);
    }
}
    
30.10.2018 / 13:44