Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception: Error. Google Maps API return status: ZERO_RESULTS for geocode_address #4

Closed
wolframteetz opened this issue Dec 2, 2015 · 6 comments

Comments

@wolframteetz
Copy link
Contributor

Every few hundred location calls I get this error.

import sys
reload(sys)
<module 'sys' (built-in)>
sys.setdefaultencoding('utf8')
origin = 'Martinsried'
duration = 90
number_of_angles=48
tolerance = 5
tolerance = 2
import isocronut
isochrone = isocronut.generate_isochrone_map(origin, duration, number_of_angles, tolerance)
Iteration 0
Iteration 1
Iteration 2
Iteration 3
Iteration 4
Iteration 5
Iteration 6
Traceback (most recent call last):
File "", line 1, in
File "isocronut.py", line 413, in generate_isochrone_map

File "isocronut.py", line 383, in get_isochrone
for i in range(number_of_angles):
File "isocronut.py", line 222, in geocode_address
if not d['status'] == 'OK':
Exception: Error. Google Maps API return status: ZERO_RESULTS

See related issues :

http://stackoverflow.com/questions/20664723/google-maps-api-v3-returning-zero-results-but-maps-google-com-showing-fine

I think one needs to provide a radius iteration to find a place with a name nearby sometimes. See e.g.

http://stackoverflow.com/questions/11754114/why-is-google-place-api-giving-me-zero-results

@wolframteetz
Copy link
Contributor Author

Test with large radius

(---begin---)
# Parse the json to pull out the geocode
if not d['status'] == 'OK':
full_url = full_url + '&radius=5000'
print "Radius 5000"
# Request geocode from address
req = urllib2.Request(full_url)
opener = urllib2.build_opener()
f = opener.open(req)
d = simplejson.load(f)
if not d['status'] == 'OK':
raise Exception('Error. Google Maps API return status: {}'.format(d['status']))
geocode = [d['results'][0]['geometry']['location']['lat'],
d['results'][0]['geometry']['location']['lng']]
return geocode
(---)

Iteration 0
Iteration 1
Iteration 2
Iteration 3
Iteration 4
Iteration 5
Iteration 6
Radius 5000
Traceback (most recent call last):
File "", line 1, in
File "isocronut.py", line 424, in generate_isochrone_map
iso = get_isochrone(origin, duration, number_of_angles, tolerance, access_type, config_path)
File "isocronut.py", line 394, in get_isochrone
iso[i] = geocode_address(data[0][i], access_type, config_path)
File "isocronut.py", line 233, in geocode_address
raise Exception('Error. Google Maps API return status: {}'.format(d['status']))
Exception: Error. Google Maps API return status: ZERO_RESULTS

Failed, so it is some other issue

@wolframteetz
Copy link
Contributor Author

Debug output appended

CALL

python
import sys
reload(sys)
sys.setdefaultencoding('utf8')
origin=[48.10892,11.451958]
duration = 90
number_of_angles=48
tolerance = 2
import isocronut
isochrone = isocronut.generate_isochrone_map(origin, duration, number_of_angles, tolerance)
from subprocess import call
call(["open", "isochrone.html"])

CODE (in get_isochrone)

for i in range(number_of_angles):
    print "Geocoding #",i
    print "Data ",data[0][i]
    iso[i] = geocode_address(data[0][i], access_type, config_path)
    time.sleep(0.5)

OUTPUT

isochrone = isocronut.generate_isochrone_map(origin, duration, number_of_angles, tolerance)
Iteration 0
Iteration 1
Iteration 2
Iteration 3
Iteration 4
Iteration 5
Iteration 6
Geocoding # 0
Data Ölschlag 3, 92334 Berching, Germany
Geocoding # 1
Data Schweinkofen 21, 92345 Dietfurt, Germany
Geocoding # 2
Data Essing, Germany
Geocoding # 3
Data Auf der Winzerer Höhe, 93059 Regensburg, Germany
Geocoding # 4
Data Unnamed Road, 93073 Neutraubling, Germany
Geocoding # 5
Data Holztraubacher Str. 15, 84066 Mallersdorf-Pfaffenberg, Germany
Geocoding # 6
Data SR65, 94339 Leiblfing, Germany
Geocoding # 7
Data Freundorf 2, 94569 Stephansposching, Germany
Geocoding # 8
Data Marklkofen, Germany
Geocoding # 9
Data Elsenbach 7, 84494 Neumarkt-Sankt Veit, Germany
Geocoding # 10
Data Hölzling 5, 84568 Pleiskirchen, Germany
Geocoding # 11
Data Kraiburg, Germany
Geocoding # 12
Data Aigner 16, 83342 Tacherting, Germany
Geocoding # 13
Data TS31, 83352 Altenmarkt, Germany
Geocoding # 14
Data Betonstraße 20, 83362 Surberg, Germany
Geocoding # 15
Data Unnamed Road, 83324 Ruhpolding, Germany
Geocoding # 16
Data Unterbergen 4, 83246 Unterwössen, Germany
Geocoding # 17
Data Kohlentalstraße 8, 6385 Schwendt, Austria
Geocoding # 18
Data Stadtberg, 6351 Kufstein, Austria
Geocoding # 19
Data Almen 4, 6335 Almen, Austria
Geocoding # 20
Data Unnamed Road, 83700 Rottach-Egern, Germany
Geocoding # 21
Data Unnamed Road, 83708 Kreuth, Germany
Geocoding # 22
Data Unnamed Road, 83661 Lenggries, Germany
Geocoding # 23
Data Unnamed Road, 83661 Lenggries, Germany
Geocoding # 24
Data Gemeinde Vomp, Austria
Geocoding # 25
Data Unnamed Road, 6108, Austria
Waiting 5s
Radius 5000
Traceback (most recent call last):
File "", line 1, in
File "isocronut.py", line 429, in generate_isochrone_map

File "isocronut.py", line 399, in get_isochrone
time.sleep(0.5)
File "isocronut.py", line 236, in geocode_address
geocode = [d['results'][0]['geometry']['location']['lat'],
Exception: Error. Google Maps API return status: ZERO_RESULTS

@wolframteetz
Copy link
Contributor Author

Exception can be caught with s.th. like this, but should be failsafe for i=0. Better idea?

I don't understand why there have to be these addresses anyway ;) I think they are also the primary reason for the outliers - geocoding Unknown Road, can lead to surprising results of course...

for i in range(number_of_angles):
    print "Geocoding #",i
    print "Data ",data[0][i]
    try:
        iso[i] = geocode_address(data[0][i], access_type, config_path)
    except:
        if i > 0:
            print "Exception caught for isocoding"
            iso[i] = iso[i-1]           
    time.sleep(0.1)

@drewfustin
Copy link
Owner

I think the proper way to handle this is:

a) initialize iso with None:

iso = [None] * number_of_angles

b) don't bother resetting iso[i] for i that fails:

    try:
        iso[i] = geocode_address(data[0][i], access_type, config_path)
    except:
        print "Exception caught for isocoding"

c) then after the i for loop, throw out all angles that failed, and fail ultimately if none of them work at all:

iso = [x for x in iso if x is not None]
if len(iso) == 0:
    raise Exception('No valid points along the isochrone were found.')

Thoughts?

@wolframteetz
Copy link
Contributor Author

Proper but still very messy because translating a known location to "unknown road, cleveland ohio" and back introduced terrible noise outside of city areas and quite some outliers.

Working on the mapbox solution instead, it's much nicer anyway.

@drewfustin
Copy link
Owner

Yeah, my other thought was: as a post-process, determine outlying radii using some outlier detection method and through those out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants