Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which API method provides the drawing of a city's boundaries?

Tags:

google-maps

Using Google Maps' API v3, how can I geocode a city name, and have a map returned with the outline of the result? usually this is a political entity with strict boundaries, like a city, municipality, etc.

Which API method should be used?

like image 501
p.campbell Avatar asked Jul 26 '15 16:07

p.campbell


People also ask

How do I find city boundaries on Google Maps?

To see it yourself, go to Google Maps and search for a city name or even a zip code. You will see a pinkish highlight around the border. Based on your zoom level, as you zoom out, Google will highlight the whole area, not just the borders, in the pink color.

What is map API used for?

A Map API (also known as Mapping API) provides location intelligence for software developers creating location-based products and services. It is the base building block for location-aware applications, feature-rich maps and the retrieval of geographic-related data.

What is the API for Google Maps?

The Google Maps API is one of those clever bits of Google technology that helps you take the power of Google Maps and put it directly on your own site. It lets you add relevant content that is useful to your visitors and customise the look and feel of the map to fit with the style of your site.


2 Answers

There isn't any API (at present) that provides that data.

Enhancement request

like image 51
geocodezip Avatar answered Nov 23 '22 20:11

geocodezip


I think you will need Tiger/Line files as referenced in this answer. You can use the data to generate polygons. Use Geocoder.geocode to search for city names. Here's a promise based function that I use:

  function locateAddress(address) {
    var deferred = $q.defer();
    if(!address) { $q.resolve(null); return; }

    var geocoder = new google.maps.Geocoder();

    var a = address;
    if(_.isObject(a)) {
      a = (a.line1 || '') + ' ' + (a.city || '') + ' ' + (a.state || '') + ' ' +  (a.zip || '');
    }

    geocoder.geocode({ 'address' : a}, function(results, status) {
      if(status === 'ZERO_RESULTS') {
        deferred.resolve(null);
        return;
      }

      var c = results[0].geometry.location;
      deferred.resolve({latitude: c.lat(), longitude: c.lng()});
    }, function(err) {
      deferred.reject(err);
    });

    return deferred.promise;
  }
like image 41
Andy Gaskell Avatar answered Nov 23 '22 18:11

Andy Gaskell