2013-03-14 2 views
1

페이지에 4 개의지도를 배치하고 각 주소에 대한 마커를 추가하는 아래 코드가 있습니다. 그러나 마커를 중심으로 매핑해야합니다. Google지도 마커에 api 센터

하면 해당 맵의 마커의 중심을 만들 경우 완전히 확실하지

<script type="text/javascript"> 
     var geocoder; 
     var map0,map1,map2,map3; 
     var markers = []; 
      function initialize() { 
      geocoder = new google.maps.Geocoder(); 
      var latlng = new google.maps.LatLng(-34.397, 150.644); 
      var mapOptions = { 
       zoom: 14, 
       center: latlng, 
       mapTypeId: google.maps.MapTypeId.ROADMAP 
      } 
      map0 = new google.maps.Map(document.getElementById("map_canvas1"), mapOptions); 
      addPostCode('@address1',map0); 
      map1 = new google.maps.Map(document.getElementById("map_canvas2"), mapOptions); 
      addPostCode('@address2',map1); 
      map2 = new google.maps.Map(document.getElementById("map_canvas3"), mapOptions); 
      addPostCode('@address3',map2); 
      map3 = new google.maps.Map(document.getElementById("map_canvas4"), mapOptions); 
      addPostCode('@address4',map3); 
      } 

      function addPostCode(address,map) { 
       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, 
        center: results[0].geometry.location, 
        name: address 
       }); 
       markers.push(marker); 
       } else { 
        alert("Geocode was not successful for the following reason: " + status); 
       } 
       }); 
      } 

.

+0

이 줄은 마커에 대해 의미가 없습니다. 'center : results [0] .geometry.location,'- 마커는'중심 ' – duncan

답변

1

글쎄, 난 당신이 여기에서 볼 수있는 작업 예제 프로그램 : JS fiddle

나는 또한 (마커는 위치에 추가되고 map.setCenter();를 사용하여 제어하는지도 이후) 마커에서 center: results[0].geometry.location을 제거하고 변경

몇 가지 클래스의 이름을 약간 변경 했으므로 원하는대로 수정하십시오. 건배!

관련 문제