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

前端 未结 2 1731
一整个雨季
一整个雨季 2020-12-29 08:01

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,

相关标签:
2条回答
  • 2020-12-29 08:34

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

    Enhancement request

    0 讨论(0)
  • 2020-12-29 08:41

    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;
      }
    
    0 讨论(0)
提交回复
热议问题