1
我處於這種情況,我需要將Google地圖自動完成功能限制爲特定的城市結果。谷歌地圖在城市內自動完成
$(document).ready(function() {
var autocomplete =
new google.maps.places.Autocomplete(
document.getElementById('addr'));
autocomplete.setTypes(['address']);
autocomplete.setComponentRestrictions({'country':'us'});
google.maps.event.addListener(autocomplete, 'place_changed',
function() {
var place = autocomplete.getPlace();
$('#name').text(place.formatted_address);
$('#lat').text(place.geometry.location.lat());
$('#long').text(place.geometry.location.lng());
var service = new google.maps.DistanceMatrixService();
service.getDistanceMatrix({
origins: [new google.maps.LatLng(
place.geometry.location.lat(),
place.geometry.location.lng())],
destinations: ['Raleigh, NC'],
travelMode: google.maps.TravelMode.DRIVING,
unitSystem: google.maps.UnitSystem.IMPERIAL
},
function(response, status) {
if (response.rows[0].elements[0].status == 'ZERO_RESULTS')
$('#distance').text('No dice!');
else
$('#distance').text(response.rows[0].elements[0].distance.text);
});
});
});
這是我一直在努力的小提琴; http://jsfiddle.net/272tx3qy/8/ 我想輸入框結果限制在北卡羅來納州羅利只(僅在羅利的街道和地址,NC)
有什麼事情可能實現使用谷歌地圖?
在此先感謝您抽出時間。