programing

이 페이지에 Google 지도 API를 여러 번 포함시켰습니다.

css3 2023. 11. 1. 22:29

이 페이지에 Google 지도 API를 여러 번 포함시켰습니다.

구글 맵 api v3를 사용하고 있습니다.저는 wpestate 부동산 워드프레스 테마를 사용하고 있습니다.이것은 템플릿 파일에 있는 내 코드입니다.

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<script src="https://maps.googleapis.com/maps/api/js?   
  v=3.exp&sensor=false&libraries=places"></script>
  <script>
var geocoder;
var map;
function initialize() {

var input = document.getElementById('address');
var options = {

componentRestrictions: {country: "in"}
};
var autocomplete = new google.maps.places.Autocomplete(input,options);
geocoder = new google.maps.Geocoder();


//var latlng = new google.maps.LatLng(18.52043030000, 73.85674369999);

var mapOptions = {
 zoom: 15,
//center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,

}

var map = new google.maps.Map(document.getElementById('googleMap'), mapOptions);

}



function codeAddress() {
 var address = document.getElementById('address').value;


 geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {

 map.setCenter(results[0].geometry.location);
  var marker = new google.maps.Marker({
      map: map,
      position: results[0].geometry.location
  });
  } else {
  alert('Geocode was not successful for the following reason: ' + status);
  }
 });
}


 google.maps.event.addDomListener(window, 'load', initialize);
 </script>

예상대로 실행되지만 콘솔에 오류가 발생합니다. "이 페이지에 Google Maps API를 여러 번 포함했습니다.예기치 않은 오류가 발생할 수 있습니다."그 지도 때문에 지도에 속성이 표시되지 않습니다.

첫번째 줄을 제거합니다.

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>

당신은 구글 지도 API를 두 번 포함하고 있습니다.

당신의 문제는 다른 사람들이 알아낸 것처럼 구글 지도의 스크립트를 복제한다는 것입니다.작동 코드는 아래 링크를 확인해주시기 바랍니다.

http://jsbin.com/husahasu/1/edit

지도를 렌더링하려면 지도의 중심을 지정해야 합니다.없으면 렌더링할 수 없습니다.당신은 또한 당신의 요소들을 위해 css를 추가해야 합니다.이것을 문서의 머리 부분에 넣습니다.

<style type="text/css">
 html { height: 100% }
 body { height: 100%; margin: 0; padding: 0 }
 #googleMap { height: 100% }
</style>

제 경우에는 맨 위 페이지와 div 이전에 라이브러리에 대한 링크를 두 번 삽입했습니다.링크를 삭제하면 됩니다.페이지에서 링크를 확인합니다.

언급URL : https://stackoverflow.com/questions/25136413/you-have-included-the-google-maps-api-multiple-times-on-this-page