When I first implemented google maps in my project, It was working fine but suddenly it stops working and starting giving error as below.
InvalidValueError: cannot set both placeId and componentRestrictions
When I removed componentRestrictions option then It working fine.
Is there any change in google maps api ?
See My below Code
// 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);
}
});
}
Or jsFiddle link.
Yes, I actually found the reason why it got stopped working on the same day.
But now I am sharing, Unintentionally I have used google map Api Experimental version as following below, which got upgraded by google time to time.
https://maps.googleapis.com/maps/api/js?key= yourapikey &v=3.exp&libraries=places
But now I have used frozen version of google map api which is v=3.27
You can find google map api version from the below link
https://developers.google.com/maps/documentation/javascript/versions
and You can find google map api Release Notes from the below link
https://developers.google.com/maps/documentation/javascript/releases
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.