我试图搜索可见地图边界内的所有城市。我怎样才能做到这一点?如何使用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”。
由于您是从google.com加载的,美国被认为是您的地区偏见。所以我希望你能收到美国佐治亚州的地理编码回应。 –
我写了完整的回复,但我不知道如何放在这里。它被我认为的管理员删除。如果您不介意,请以无格式的方式阅读我的评论。谢谢。 查看此页面中的列表:https://developers.google.com/places/documentation/supported_types,我意识到第一个列表中的几乎所有项目都会返回值,但不会返回第二个列表。唯一的项目返回值是'政治',它只返回1而不是20。 – dtnam