steve8x8 / geotoad

Geocaching query tool written in Ruby
https://buymeacoffee.com/steve8x8
Other
28 stars 8 forks source link

Google Maps API call fails #362

Closed FredFronky closed 5 years ago

FredFronky commented 5 years ago

Hi there, Just trying to download some caches before I go away, and the location finding feature seems to be broken, at least for me. Was able to fix by manually setting coords in seach.rb, but this is obviously not ideal. Running with geotoad.rb --delimiter='|' --distanceMax=10 --output='D:/' --queryType=location Adelaide, though even inputting coords gives the same error.

( o ) "location" search for "Adelaide", constraining to 10 miles
D: geocode looking up address "Adelaide"
D: geocode url: http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address=Adelaide
D: cachefile: C:/Users/_/.geotoad/cache/maps.googleapis.com/maps/api/geocode/xml_sensor_false_address_Adelaide
D: ====+ Fetch URL: http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address=Adelaide
D: ====+ Fetch File: C:/Users/_/.geotoad/cache/maps.googleapis.com/maps/api/geocode/xml_sensor_false_address_Adelaide
D: no local cache file found for C:/Users/_/.geotoad/cache/maps.googleapis.com/maps/api/geocode/xml_sensor_false_address_Adelaide
D: sleep 0.1 seconds
D: Fetching URL [http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address=Adelaide]
D: No proxy found in environment, using standard HTTP connection.
D: Cookie not added to http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address=Adelaide
D: GET to /maps/api/geocode/xml?sensor=false&address=Adelaide, headers are User-Agent Accept Accept-Language Accept-Encoding Accept-Charset Referer
D: http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address=Adelaide successfully downloaded.
D: Content-Encoding "gzip" for http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address=Adelaide
D: gunzip content
D: 300 bytes retrieved from http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address=Adelaide
D: Returning 300 bytes: <?xml version="1.0" e(...)>
</GeocodeResponse>
D: geocode data: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<GeocodeResponse>\n <status>REQUEST_DENIED</status>\n <error_message>You must use an API key to authenticate each request to Google Maps Platform APIs. For additional information, please refer to http://g.co/dev/maps-no-account</error_message>\n</GeocodeResponse>\n"
D: returning: [nil, nil, nil, "", 0]
D: geocoder returned: a:nil x: y:
 ***  Google Maps failed to determine the location of Adelaide
 ***  Search "location" for "Adelaide" unknown.
 ***  Check for special characters or try a "coord" search instead.
D: waypoints extracted: 0, combined: 0
 ***  No valid query or no caches found in search, exiting early.

Sorry for the brief error description, happy to elaborate more when I get back.

steve8x8 commented 5 years ago

Hm, looks like Google has been closing down yet another API. GeoToad has been using v3 (XML interface) while https://developers.google.com/maps/documentation/geocoding/ now describes JSON requests. This must have happened some time ago (apparently already in 2018?=)... I didn't notice because geocoding had been rather problematic for me all the time.

There are two places where their API is used: for conversion of "location" to "coordinates" (from the command line) and for conversion of (cache) coordinates to street addresses. Both now appear to require usage of an API key - which must be purchased, and I suppose it would violate the rules to set it free inside an open-source code. You would be free to purchase your own key, and with some code adjustments, GeoToad would be able to read it from a local file and use it, fully under your control. [If you're in a hurry, and prefer the Google way, you may probably hardcode the key into lib/geocode.rb - I'd first suggest to replace the string "sensor=false" in the @@maps_base definition with "key=YOUR_API_KEY") and get along with the XML request; rewriting this to analyze JSON responses should be rather straightforward.]

While this would supposedly solve your issue, I wouldn't be happy with it, and I'd be unable to test the whole thing.

So there must be another solution - I'll look into Nominatim (https://wiki.openstreetmap.org/wiki/Nominatim) which looks promising. GeoToad already caches results, adding a delay of 1 second per request would only slow down HTML output generation (once), this seems feasible. I can see though that there are about a dozen Adelaides around (only some of which are dupes): https://nominatim.openstreetmap.org/search.php?q=Adelaide&polygon_geojson=1&viewbox= - I guess you're not in Washington State nor in Colombia?

Give me a few days to figure out the details.

steve8x8 commented 5 years ago

There's a first shot at the issue in the work-in-progress patch set now. I'll do some more testing (in particular, with special characters in the search string) before committing upstream. Feel free to join me ;)

steve8x8 commented 5 years ago

Just for documentation purposes, there was a similar issue (with an easier (?) fix) in #279.

steve8x8 commented 5 years ago

Please try (using "patch -p1" as usual) the attached diff: 362-geocoder.diff.txt which has been in use for more than a day now (but not for location queries) - it hasn't shown any regressions yet. Torture it...

Caveat: "html" will no longer include reverse address lookups, there's "html-revloc" now - which is heavily penalized by adding a 5-second delay per address query.

The next official release is a few weeks away, but if there are no major issues with the patch I'll commit the changes.

madaxeman2495 commented 5 years ago

I'm having the same problem.

steve8x8 commented 5 years ago

I'm having the same problem.

Can you try the git head (which contains the fix), or if you cannot, apply the patch to the previous version? It will take a while longer until I'll be able to roll another release.

steve8x8 commented 5 years ago

Fixed in 3.29.1