Google Maps Latitude Longitude does not find address, but exists in Google Maps

I am using the postal code search tool. As an example: I am looking for the zip code: 04291-020 the return is: Rua Muller Carioba. See that there are 2 letters L in the name. Putting this same address in the Google URL to fetch 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 one of the two L's from the name, the result comes correctly. So my doubt is: how to make this search for LAT / LNG work the same way as Google Maps? Because in Google Maps it finds either with 1 L or with 2 L.

Author: riki481, 2017-09-21

2 answers

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

Still anyway, your URL has an error: spaces!

When you make a request via URL with parameters (called Query String), you must replace the 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, neither google maps itself 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!

 0
Author: Bruno Felipe, 2017-09-21 12:03:59

The problem of consuming this method from API from google.maps , is that it has a limit of daily requests, in this 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 if the operation fails, it will set a time of 3 seconds and redo, forcing the method (native to API) Geocoder fetching the address via latitude and longitude.

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);
    }
}
 0
Author: Igor Carreiro, 2018-10-30 12:44:50