Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google api geocoding returns json object different than official docs

I've been successfully using the google api for geocoding, but when I originally set it up I noticed that the object returned is not quite the same as described in the google documentation here: https://developers.google.com/maps/documentation/geocoding/#GeocodingResponses

I used console.dir to inspect the object in chrome.

Unless I've misunderstood (quite likely), I can retrieve the latitude and longitude for the supplied address as follows:

lat = results[0].geometry.location.lat;
lng = results[0].geometry.location.lng;

Except, that wasn't working, and when I investigated I found that lat and lng were at results[0].geometry.location.d and results[0].geometry.location.e respectively.

All good until today it stopped working. Investigating I found that lat & lng are being returned via results[0].geometry.location.k & results[0].location.A.

Presumably this will break again before too long.

If I inspect results[0].geometry.location.lat it contains this:

function (){
\"use strict\";
return this[a]}

Anyone recognise that?

like image 893
terraling Avatar asked Mar 11 '14 22:03

terraling


People also ask

How accurate is Google geocoding?

Results. Respectively 81.4% and 84.4% of addresses were geocoded to the exact address (65.1% and 61.4%) or to the street segment (16.3% and 23.0%) with methods A and B. In the reference layer, geocoding accuracy was higher in urban areas compared to rural areas (74.4% vs.

Is Google Maps API accurate?

For the most part its working fine - returning accurate results. But on rare occasions - it will record a GPS around 20 miles away.

What does geocode return?

The geocoder does its best to provide a street address that is readable for both the user and locals. To achieve that goal, it returns street addresses in the local language, transliterated to a script readable by the user if necessary, observing the preferred language.

What happens when you exceed the Google geocoding API rate limit py4e?

According to Google's API Usage and Billing page, there is a limit of 50 requests per second. If you exceed this amount, subsequent requests to the API will fail with the OVER_DAILY_LIMIT or OVER_QUERY_LIMIT status code and the geocoded data will not be returned.


1 Answers

The results returned from the geocode-method of the Javascript-Geocoder is already translated to be used with the Javascript-API(the linked documentation is for the Geocoding-Webservice, not for the Maps-Javascript-API).

geometry.location is not a plain object, it's a google.maps.LatLng

you must use the methods lat() and lng() of geometry.location to retrieve latitude and longitude.

Specification of GeocoderGeometry

In your case that would mean using it like this:

lat = results[0].geometry.location.lat(); etc.

like image 192
Dr.Molle Avatar answered Sep 24 '22 17:09

Dr.Molle