Question

I am trying to get Lat/Lon for a list of locations from an address. It works for most addresses, but certain ones fail and return Zero Results.

Take this address as an example: 1045 Mono Way, Sonora, CA 95370

As you can see, that is a valid address on Google Maps - no issues there.

When pinging the Geocoder Api, I am encoding the address using urlencode(). This is the encoded address: 1045%20Mono%20Way%2C%20Sonora%2C%20CA%2095370

This is the link that I am accessing: https://maps.googleapis.com/maps/api/geocode/xml?address=1045%20Mono%20Way%2C%20Sonora%2C%20CA%2095370&sensor=false

As you can see, zero results.

Now, if you change the first part of the address (1045) to any other number (e.g. 1044), you will get valid results.

I am lost.

Need help.

Please ;)

BTW, I am using this reply to get the lat/lon from the API: Google Maps - converting address to latitude & longitude - PHP backend?

Was it helpful?

Solution

I would bet that address just doesn't exist. The addresses are provided by local government, typically in a range of numbers that corresponds to a stretch of street. The fact that trying odd numbers doesn't work (1045, 1047, 1049) but even numbers do (1044, 1046, 1048) suggests that the addresses on one side of the road are not there. Or at least not in the dataset provided by the city or county.

The ideal solution would be a "fuzziness" argument to the API call, which would return a location similar to what their Maps site is. But since we can't rewrite third party APIs, I'd suggest checking for a "ZERO_RESULTS" response, and then resubmitting the request with just the street name if needed.

Also, you can do a geocode search without your API key, so you may want to keep that out of your question!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top