Domanda

This is my JS code to get lon and lat of an address.

in 99% of the time it works OK.... but sometimes I get ZERO_RESULTS status...

if (geocoder) {
    geocoder.geocode({'address': address, 'language':'it'}, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            $('#frm_company_lat').val(results[0].geometry.location.lat());
            $('#frm_company_lon').val(results[0].geometry.location.lng());

            can_submit = true;
            $('#company_frm').trigger("submit");
        } else{
            top.console.debug(address);
            top.console.debug(status);
            alert("Cannot get lon in lat: "+ address);
            //can_submit = true;
            //$('#company_frm').trigger("submit");
        }
    });
}

The address is nothing special and if I look for it in google maps directly, it shows...

If I try to fetc JSON directly (via direct url) I get the same result!

http://maps.googleapis.com/maps/api/geocode/xml?address=Via%20Selo%2010a,%2047122%20Forli,%20Italia&sensor=false

PLEASE ADVISE

È stato utile?

Soluzione

It looks like sometimes is better to remove the postal number/zip out of the address query...

so in the specific case if I remove 47122 it works OK.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top