title: Google maps web services/JavaScript API - problems with the bounding boxes
body: <p>I need to get a decent bounding box for any given city. As of now, I know of no way to do it, but through the google maps API <code>geocode</code> function. However, there are problems.</p>
  
  <p>For instance, consider Abu Dhabi. </p>
  
  <p>Here is the code (using python <a href="http://py-googlemaps.sourceforge.net/#googlemaps.GoogleMaps.geocode" rel="nofollow noreferrer">googlemaps</a> package):</p>
  
  <pre><code>&gt;&gt;&gt; d = gmaps.geocode('Abu Dhabi, AE')
  &gt;&gt;&gt; pp.pprint(d)
  { u'Placemark': [ { u'AddressDetails': { u'Accuracy': 4,
                                           u'Country': { u'AdministrativeArea': { u'AdministrativeAreaName': u'Abu Dhabi',
                                                                                  u'Locality': { u'LocalityName': u'Abu Dhabi'}},
                                                         u'CountryName': u'United Arab Emirates',
                                                         u'CountryNameCode': u'AE'}},
                      u'ExtendedData': { u'LatLonBox': { u'east': 54.8789043,
                                                         u'north': 24.7912388,
                                                         u'south': 24.1412558,
                                                         u'west': 53.8544291}},
                      u'Point': { u'coordinates': [54.3666667, 24.4666667, 0]},
                      u'address': u'Abu Dhabi - United Arab Emirates',
                      u'id': u'p1'}],
    u'Status': { u'code': 200, u'request': u'geocode'},
    u'name': u'Abu Dhabi, AE'}
  </code></pre>
  
  <p>The problem is that the returned <code>LatLonBox</code> is way too large - its diagonal is more than 126km long. With all due respect to Abu Dhabi, I do not think the city is that big.</p>
  
  <p>Interestingly enough, the JavaScript API returns two boxes. Assuming <code>results</code> is the result of invoking <code>google.maps.Geocoder.geocode</code>  on 'Abu Dhabi', we have two boxes:</p>
  
  <ul>
  <li><code>results[0].geometry.bounds = ((24.1776, 54.30012), (24.5413, 54.7751))</code></li>
  <li><code>results[0].geometry.viewport = ((24.1413, 53.8544), (24.7912, 54.8789))</code></li>
  </ul>
  
  <p>Where the <code>viewport</code> is exactly the <code>LatLonBox</code> returned by the web services API. The <code>bounds</code>, on the other hand, looks much better both in terms of the size and the location - the below image depicts both boxes:
  <img src="https://i.stack.imgur.com/K4mzO.png" alt="enter image description here"></p>
  
  <p>At first, I have suspected the python package to omit the <code>bounds</code> from the final result, but examining the json returned by the google maps web service reveals that no <code>bounds</code> box is returned by the web service - the python dictionary describing the result is an exact mirror of the returned json.</p>
  
  <p>So, my question is how can I get a decent bounding box when using the web services API? Or is there an alternative API altogether? Does anyone have any experience with a non google maps API to get this kind of information?</p>
  
  <p>Thanks.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Another interesting twist. While some cities have huge bounding (or viewport) boxes, some have tiny ones. For instance, the diameter of one bounding Adelaide, AU is only 7km, which is, of course, too small:
  <img src="https://i.stack.imgur.com/Vvnvr.png" alt="enter image description here"></p>