1
없이

단일 위치에서 여러 마커 처리에 케이시 P 토마스의 솔루션을 사용 :Google지도 마커 클러스터 러 플러스 지오 코딩

예 : http://maps.caseypthomas.org/ex/MarkerClustererPlus/exCoincidentMarkers_SharedInfowindow_wGeocoding.html

그것은 잘 작동하고 하나의 정보 창에 내용을 결합, 그러나 지도를 위반하는 API에 지오 코딩 한계가있는 것 같습니다. 전달할 공동 목록이 있으므로 주소를 지오 코딩해야 할 필요가 없습니다.

제 질문은 어떻게 JS에서 지오 코딩 기능을 우회하여 그 방식으로지도를 작성할 수 있습니까?

감사

코드 내가 사용하고

:

 var map; 

    //marker clusterer 
    var mc; 
    var mcOptions = {gridSize: 20, maxZoom: 17}; 

    //global infowindow 
    var infowindow = new google.maps.InfoWindow(); 

    //geocoder 
    var geocoder = new google.maps.Geocoder(); 

    //Content and Geos 
    var address = new Array(<?php echo $tweetgeos;?>); 
    var content = new Array(<?php echo $tweets;?>); 


    function createMarker(latlng,text) { 
     var marker = new google.maps.Marker({ 
      position: latlng 
     }); 

     ///get array of markers currently in cluster 
     var allMarkers = mc.getMarkers(); 


     //check to see if any of the existing markers match the latlng of the new marker 
     if (allMarkers.length != 0) { 
      for (i=0; i < allMarkers.length; i++) { 
       var existingMarker = allMarkers[i]; 
       var pos = existingMarker.getPosition(); 

       if (latlng.equals(pos)) { 
        text = text + " & " + content[i]; 
       } 
      } 
     } 

     google.maps.event.addListener(marker, 'click', function() { 
      infowindow.close(); 
      infowindow.setContent(text); 
      infowindow.open(map,marker); 
     }); 

     return marker; 
    } 


    function geocodeAddress(address,i) { 
     geocoder.geocode({'address': address}, function(results, status) { 

      if (status == google.maps.GeocoderStatus.OK) { 

       var marker = createMarker(results[0].geometry.location,content[i]); 
       mc.addMarker(marker); 

      } else { 
       alert("Geocode was not successful for the following reason: " + status); 
     } 

     }); 
    } 

    function initialize(){ 
     var options = { 
      zoom: 5, 
      center: new google.maps.LatLng(51.50733,-0.12768), 
      mapTypeId: google.maps.MapTypeId.ROADMAP 
     }; 

     map = new google.maps.Map(document.getElementById('map'), options); 


     //marker cluster 
     mc = new MarkerClusterer(map, [], mcOptions); 
     for (i=0; i<address.length; i++) { 
      geocodeAddress(address[i],i); 
     } 
    } 

    google.maps.event.addDomListener(window, 'load', initialize); 

답변

0

당신은 당신의 좌표와 지오 코딩 API를 호출하지 않고 직접 마커를 초기화 할 수 있습니다.

// Change address Array to an Array of JS Objects 
var address = [ 
    { 
     latitude: lat1, 
     longitude: lng1, 
    }, 
    { 
     latitude: lat2, 
     longitude: lng2, 
    }, 
    ... 
]; 

// In function:createMarker() 
var myLatLng = new google.maps.LatLng(latlng.latitude, latlng.longitude); 
var marker = new google.maps.Marker({ 
    position: myLatLng, 
}); 

// In function:initialize() 
for (i=0; i<address.length; i++) { 
    createMarker(address[i], content[i]); 
} 
+0

위대한 작품! 감사! –

관련 문제