2011-08-16 7 views
3

마커를 설정하고 해당 마커의 위도와 경도를 얻는 데 문제가 있습니다. 어떻게 구글에서 V3의 APIGoogle지도 API v3 마커 설정 및 포인트 받기

var myLatlng = new google.maps.LatLng(-34.397, 150.644); 
     var myOptions = { 
      zoom: 8, 
      center: myLatlng, 
      mapTypeId: google.maps.MapTypeId.ROADMAP 
     }; 
var map = new google.maps.Map(document.getElementById("divGoogleMaps"), myOptions); 

google.maps.event.addListener(map, 'click', function() { 

}); 

이 내 시작 코드를 매핑하는 것을 할 수 있습니다.

답변

3

시작하는 데 도움이되는 유용한 정보가있는 Google Maps API doc 웹 사이트를 확인해야합니다.

google.maps.event.addListener(map, 'click', function(e) { 
      placeMarker(e.latLng, map); 
     }); 
     } 

     function placeMarker(position, map) { 
     var marker = new google.maps.Marker({ 
      position: position, 
      map: map 
     }); 
     map.panTo(position); 
     } 

http://code.google.com/apis/maps/documentation/javascript/basics.html

은 여기에서 마커를 설정하고 위치를 얻는다. 당신이 마커에 이벤트 리스너를 첨부 할 경우

+0

이 코드를 끝내면 도움이됩니다. 지도에서 하나의 마커 만 가질 수 있으며이 마커는지도 '코드'에서 사용자가 클릭 할 때 설정됩니다. google.maps.event.addListener (지도, '클릭', 함수 (이벤트) { \t \t \t if (self.marker! = NULL) \t \t \t \t self.marker.setMap (NULL) \t \t \t self.value = 새은 google.maps.LatLng (event.latLng.lat() event.latLng.lng()); \t \t \t \t self.marker = 새로운 google.maps.Marker ({ \t \t \t \t 총수 : 0 self.value\t \t \t}); \t \t \t self.zoom = map.getZoom(); \t \t \t self.marker.setMap (map); \t}); – user821738

0
var marker = new google.maps.Marker({ 
    position: myLatlng, 
    map: map, 
    title:"Hello World!" 
}); 

Google Maps API v3

에서 직접 촬영, 당신은 여전히에 신선한 참조가 동안,지도에 추가 직후에 그것을하는 것이 좋습니다 (일반적으로 마커를 추가하여 마커를 반복하는 경우).

+2

google.maps.event.addListener (지도, {), 기능 ('click'이벤트를 \t \t \t 경우 (self.marker = NULL) \t \t \t \t self.marker.setMap (널)! \t \t \t self.value = 새은 google.maps.LatLng (event.latLng.lat() event.latLng.lng()); \t \t \t \t self.marker = 새로운 google.maps.Marker ({ \t \t \t \t 게재 순위 : 자체. 값 \t \t \t}); \t \t \t self.zoom = map.getZoom(); \t \t \t self.marker.setMap (map); \t}); 위의 코드 – user821738

+0

은 내 문제와 관련하여 도움이되었습니다. 충고에 감사하다 – user821738

관련 문제