-1

우편 번호를 통한 검색과 함께 여러지도 표시자를 표시하는 스크립트를 작성했거나 주소가 여러 표식과 사용자의 주어진 위치 사이의 거리를 표시하는 주소도 있지만 .. 일부 콘텐츠가있는 infoWindow를 표시하려고합니다. 내가 각 마커에 쓸 것입니다 ... 누구든지 나를 도울 수 있습니까 ??Google지도 Javascript Api. 지도 표시 자 infoWindow 표시

스크립트는 다음과 같이 진행됩니다

var features = [ 
     { 
     position: new google.maps.LatLng(38.089374, 23.809245), 
     type: 'info' 

     }, { 
     position: new google.maps.LatLng(37.865212, 23.744748), 
     type: 'info' 
     }, { 
     position: new google.maps.LatLng(37.997172, 23.693429), 
     type: 'info' 
     }, { 
     position: new google.maps.LatLng(37.934769, 23.879542), 
     type: 'info' 
     }, { 
     position: new google.maps.LatLng(38.003720, 23.886767), 
     type: 'info' 
     }, { 
     position: new google.maps.LatLng(38.027083, 23.850951), 
     type: 'info' 
     }, { 
     position: new google.maps.LatLng(37.944077, 23.661457), 
     type: 'info' 
     }, { 
     position: new google.maps.LatLng(38.017348, 23.796585), 
     type: 'info' 
     }, { 
     position: new google.maps.LatLng(37.955754, 23.677229), 
     type: 'info' 
     }, { 
     position: new google.maps.LatLng(37.971261, 23.756350), 
     type: 'info' 
     }, { 
     position: new google.maps.LatLng(37.990022, 23.720621), 
     type: 'info' 
     }, { 
     position: new google.maps.LatLng(38.050031, 23.752440), 
     type: 'info' 
     }, { 
     position: new google.maps.LatLng(38.464754,23.615317), 
     type: 'info' 
     }, { 
     position: new google.maps.LatLng(37.943692, 23.748214), 
     type: 'info' 
     }, { 
     position: new google.maps.LatLng(39.544696, 21.775843), 
     type: 'info' 
     }, { 
     position: new google.maps.LatLng(40.668344, 22.889161), 
     type: 'info' 
     }, { 
     position: new google.maps.LatLng(40.662039, 22.911951), 
     type: 'info' 
     }, { 
     position: new google.maps.LatLng(40.573629, 23.025070), 
     type: 'info' 
     }, { 
     position: new google.maps.LatLng(40.303271, 21.804128), 
     type: 'info' 
     } 

    ]; 



    // edw oi kaloi oi markers. 
    features.forEach(function(feature) { 
     var marker = new google.maps.Marker({ 
     position: feature.position, 
     icon: icons[feature.type].icon, 

     map: map 
     }); 



    }); 
+0

게시 된 코드에 [InfoWindows] (https://developers.google.com/maps/documentation/javascript/infowindows)가 없습니다. – geocodezip

+0

예, InfoWindow를 삽입하려고했지만 아무리 제대로 작동하지 않아도됩니다. 볼 수 있듯이 var 기능은 내 마커이며 infowindow에 대한 코드 조각을 넣어도 표시되지 않거나 클릭 할 때 창을 볼 수 있지만 비어 있습니다 ... (작성하지 않은 경우 용서하십시오. 명확한 이유는 이것입니다.) – elusivesmoke

+0

정보 창을 삽입하려고 할 때 코드가 어떻게 보이는지 보여 줄 수 있습니까? 그러면 우리가 뭘 잘못했는지 말할 수 있습니다. – Jacob

답변

0

이 같은 뭔가! 나는 당신의 질문에 따라 나는 내가 그것을했을 것이라고 생각하는 방식을 공유하고 있지만 전문가는 아닙니다.

참고 코드를 테스트하지 않았으므로 확인해보십시오. 문제가 있으면 알려주십시오.

 var markers = [ 
     { 
      lat: 38.089374, 
      lng: 23.809245, 
      type: 'info' 

     }, { 
      lat: 40.668344, 
      lng: 22.889161, 
      type: 'info' 
     }, { 
      lat: 40.573629, 
      lng: 21.804128, 
      type: 'info' 
     }]; 
     var bounds = new google.maps.LatLngBounds(); 
     var mapOptions = { 
     mapTypeId: google.maps.MapTypeId.TERRAIN, 
     mapTypeControl: false, 
     fullscreenControl: false, 
     streetViewControl: false, 
     zoomControl: true, 
     }; 
     var mapDiv = document.getElementById('mapdiv'); 
     var map = new google.maps.Map(mapDiv, mapOptions); 
     var location; 
     if(markers.length > 0){ 
      for(var i=0; i<markers.length; i++){ 
       location = new google.maps.LatLng(markers[i].lat, markers[i].lng 
     ); 
     bounds.extend(location); 
     var marker = new google.maps.Marker({ 
         position: location, 
         map: map, 
         animation: google.maps.Animation.DROP, 
        }); 
     var content = '<div class="someclass">Your content goes here.</div>'; 
     var infowindow = new google.maps.InfoWindow({maxWidth:350}); 

     google.maps.event.addListener(marker, 'mouseover' ,(function(marker,content,infowindow) { 
       return function() { 
        infowindow.setContent(content); 
        infowindow.open(map, marker); 
       }; 
     }) (marker,content,infowindow)); 
    } 
} 

마지막으로 문제를 해결하는 데 도움이된다면이를 수락하는 것을 잊지 마십시오.

+0

대단히 감사합니다 !! 참으로 작동합니다 !! 하지만 각 마커의 내용을 다르게 표시해야 할 필요가 있습니다. 예를 들어 첫번째 마커에는 infowindow라는 문구가 있고 "Hello world"라는 구문이 있습니다. 두 번째 문구에는 "Hello flowers"라는 문구가 있습니다. 매우 고맙습니다.하지만 첫 번째 솔루션에 다시 한번 감사드립니다. :) – elusivesmoke