2012-07-03 76 views
0

我试图搜索可见地图边界内的所有城市。我怎样才能做到这一点?如何使用Google Maps v3搜索某个地区的城市?

下面是我试图做的:

$.fn.gmap3.geocoder.geocode({ 'address': 'Georgia' }, function(results, status) { 
    if (status == google.maps.GeocoderStatus.OK) { 
     globalMap.setCenter(results[0].geometry.location); 
     var resultBounds = new google.maps.LatLngBounds(
      results[0].geometry.viewport.getSouthWest(), 
      results[0].geometry.viewport.getNorthEast() 
     ); 
     globalMap.fitBounds(resultBounds); 
     // get cities in the map 
     var service = new google.maps.places.PlacesService(globalMap); 
     var request = { 
      bounds: resultBounds, 
      types: ['locality'] 
     }; 
     service.search(request, function (results, status) { 
      debugger; 
     }); 
    } 
}); 

但结果是ZERO_RESULTS。也许原因是结果被限制在半径50,000米?

任何人都知道如何解决我的问题?非常感谢。

--UPDATE--

谢谢,肖恩,为仔细阅读我的文章,并给予详细的反馈。

这就是我如何参考lib:

src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"
我还向地理编码功能添加了更多细节以获得更精确的结果。但我仍然没有得到我想要的结果。

查看此页面上的列表:https://developers.google.com/places/documentation/supported_types,我意识到第一个列表中的几乎所有项目都会返回值,但不会返回第二个列表。唯一的项目返回值是“政治”,并将其对矫正后返回的只有1个,而不是20

这是我的代码:

 
this.setCenterByAddress = function (address, region) { 
    $.fn.gmap3.geocoder.geocode({ 'address': address, 'region': region }, function (results, status) { 
     if (status == google.maps.GeocoderStatus.OK) { 
      globalMap.setCenter(results[0].geometry.location); 
      var resultBounds = new google.maps.LatLngBounds(
       results[0].geometry.viewport.getSouthWest(), 
       results[0].geometry.viewport.getNorthEast() 
      ); 
      globalMap.fitBounds(resultBounds); 
      // get cities in the map 
      var service = new google.maps.places.PlacesService(globalMap); 
      var request = { 
       bounds: resultBounds, 
       types: ['country', 
       'administrative_area_level_1', 
       'administrative_area_level_2', 
       'administrative_area_level_3', 
       'colloquial_area', 
       'country', 
       'floor', 
       'geocode', 
       'intersection', 
       'locality', 
       'natural_feature', 
       'neighborhood', 
       'political', 
       'point_of_interest', 
       'post_box', 
       'postal_code', 
       'postal_code_prefix', 
       'postal_town', 
       'premise', 
       'room', 
       'route', 
       'street_address', 
       'street_number', 
       'sublocality', 
       'sublocality_level_4', 
       'sublocality_level_5', 
       'sublocality_level_3', 
       'sublocality_level_2', 
       'sublocality_level_1', 
       'subpremise', 
       'transit_station'] 
      }; 
      service.search(request, function (results, status) { 
       debugger; 
      }); 
     } 
    }); 
} 

更多信息:即使在位置和半径使用相同的价值回归。我使用免费地图并一直接收“OVER_QUERY_LIMIT”。

回答

1

除非使用locationradius选项,否则不应将其限制为50,000米;您正在使用bounds。我建议退出一个级别并挖掘从开始呼叫返回到geocode的结果,因为您使用PlacesService似乎是正确的。 resultBounds对象的内部值是什么?我还注意到,当您调用地理编码器时,您没有使用地区偏差,可能是因为“格鲁吉亚”不够具体。例如,你是指俄罗斯联邦或美国的区域吗?我不确定您使用哪个网址加载Google Maps API场所库,但这也可能会影响您的结果。

我会仔细检查从地理编码器返回的结果,因为除非我错过了某些东西,否则看起来您的基本方法是正确的。

+0

dtnam

+0

由于您是从google.com加载的,美国被认为是您的地区偏见。所以我希望你能收到美国佐治亚州的地理编码回应。 –

+0

我写了完整的回复,但我不知道如何放在这里。它被我认为的管理员删除。如果您不介意,请以无格式的方式阅读我的评论。谢谢。 查看此页面中的列表:https://developers.google.com/places/documentation/supported_types,我意识到第一个列表中的几乎所有项目都会返回值,但不会返回第二个列表。唯一的项目返回值是'政治',它只返回1而不是20。 – dtnam

0

不能围绕一个特定的经纬度与地理编码API/Places API的通过地方收益高于两个近更

请参阅谷歌Places API的论坛this thread

这是不可能的将Google Places API作为政治结果 (如地区,邻里和次级地址)返回到 ,用于标识请求的区域,并且每个请求限制为两个。

相关问题