Reputation: 62736
Given:
Question: determine whether the given geopoint belongs to the city.
My current solution is trivial:
So far so good. Even if it is not the best of algorithms, it is surely the simplest. However, there are problems. Take for instance:
The GoogleMaps.reverse_geocode(57.14369, -2.22314)
yields the following result:
{ u'Placemark': [ { u'AddressDetails': { u'Accuracy': 6,
u'Country': { u'CountryName': u'UK',
u'CountryNameCode': u'GB',
u'Thoroughfare': { u'ThoroughfareName': u'A944'}}},
u'ExtendedData': { u'LatLonBox': { u'east': -2.2200414,
u'north': 57.1480762,
u'south': 57.1453783,
u'west': -2.2239393}},
u'Point': { u'coordinates': [-2.221984, 57.1467683, 0]},
u'address': u'A944, Aberdeen, Aberdeen City AB15, UK',
u'id': u'p1'}],
u'_id': 7635459717214061L,
u'loc': [-2.2231, 57.1437]}
The problem is that the formatted address (A944, Aberdeen, Aberdeen City AB15, UK
) is not broken into details - the returned AddressDetails
is essentially useless.
So, it looks like one has to parse the returned address
manually, which seems to be a real PITA in a general case.
I would like to know how other folks solve this problem. Using the google maps web services API is not a requirement.
Thanks.
Upvotes: 0
Views: 870
Reputation: 12973
The reverse geocoding web service for http://maps.googleapis.com/maps/api/geocode/json?latlng=57.14369,-2.22314&sensor=false
yields far more data than you have posted from the Python package, including
{
"results" : [
{
"address_components" : [
{
"long_name" : "A944",
"short_name" : "A944",
"types" : [ "route" ]
},
{
"long_name" : "Aberdeen City",
"short_name" : "Aberdeen City",
"types" : [ "administrative_area_level_2", "political" ]
},
...
which seems to fit the bill. You get "Aberdeen City".
Upvotes: 1