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

Asked

Viewed 868 times

1

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

  • what type of application is being used? as your report tested in the browser link street Muller Carioba and I got the result normally, maybe your application should not be passing correctly the search parameter, with the information you posted is not clear enough, I ask you to edit the question and put more information and sections of the code.

  • Okay, edited question.

2 answers

0

The problem of consuming this method of API of google maps., is that it has a daily request limit, in this case, you have to force the request recursively. That is, whenever you do this and return the error "ZERO_RESULTS, You take the appointment again. Clearly seeing 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 of API) Geocoder searching 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

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

Still anyway, your URL has an error: spaces!

When you perform a request via URL with parameters (called Query String), you must replace the spaces by %20 or +, for the browser to understand your request.

Therefore, if you run the query below: (already removing the number 100, since with the number 100, not even 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!

  • All right, buddy, I understand the issue of spaces, which in this case does not influence the outcome. However I need the address to have the residence number to have accuracy in LAT/LNG.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.