[英]componentRestrictions is not working with placeId in reverse Geocoding in google maps
当我在项目中首次实现google maps时,它工作正常,但突然停止工作,并开始出现如下错误。
InvalidValueError:不能同时设置placeId和componentRestrictions
当我删除componentRestrictions选项时,它工作正常。
谷歌地图api有什么变化吗?
请参阅我的以下代码
// Initialize the map.
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 8,
center: {lat: 40.72, lng: -73.96}
});
var geocoder = new google.maps.Geocoder;
var infowindow = new google.maps.InfoWindow;
document.getElementById('submit').addEventListener('click', function() {
geocodePlaceId(geocoder, map, infowindow);
});
}
// This function is called when the user clicks the UI button requesting
// a reverse geocode.
function geocodePlaceId(geocoder, map, infowindow) {
var placeId = document.getElementById('place-id').value;
geocoder.geocode({
'placeId': placeId,
componentRestrictions: {
country: 'USA'
}
}, function(results, status) {
if (status === 'OK') {
if (results[0]) {
map.setZoom(11);
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
infowindow.setContent(results[0].formatted_address);
infowindow.open(map, marker);
} else {
window.alert('No results found');
}
} else {
window.alert('Geocoder failed due to: ' + status);
}
});
}
或jsFiddle链接。
是的,我实际上找到了它在同一天停止工作的原因。
但现在我正在共享,我无意中使用了以下Google Map Api实验版本,该版本已由Google不定期升级。
https://maps.googleapis.com/maps/api/js?key= yourapikey &v = 3.exp&libraries = places
但是现在我使用的是冻结版本的Google Map API,其v = 3.27
您可以从以下链接中找到Google Map API版本
https://developers.google.com/maps/documentation/javascript/versions
并且您可以从以下链接中找到Google Map API发行说明
https://developers.google.com/maps/documentation/javascript/releases
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.