簡體   English   中英

componentRestrictions無法在Google地圖的反向地址編碼中與placeId一起使用

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM