2011-12-29 3 views
0

내가 내 구글 API에 사용자 정의 마커를 추가하려고 클릭 : 그 마커를 클릭 할 때를 제외하고 잘 작동, 내가 어떤 이벤트를이 없다 더 이상 :구글 API를 마커 +

var map = new GMap2(document.getElementById("map_canvas")); 
map.setCenter(new GLatLng(0, 0), 5); 
map.addControl(new GLargeMapControl3D()); 
map.addControl(new GMenuMapTypeControl()); 

var myIcon = new GIcon(G_DEFAULT_ICON); 
myIcon.image = "http://farm3.staticflickr.com/2140/1911601567_49d97f3318.jpg"; 
myIcon.iconSize = new GSize(80, 60); 
markerOptions={}; 
//markerOptions = { icon:myIcon }; // if I uncomment this : no click anymore 

var bounds = map.getBounds(); 
var southWest = bounds.getSouthWest(); 
var northEast = bounds.getNorthEast(); 
var lngSpan = northEast.lng() - southWest.lng(); 
var latSpan = northEast.lat() - southWest.lat(); 

var point = new GLatLng(southWest.lat() + latSpan * Math.random(), southWest.lng() + lngSpan * Math.random()); 
var marker = new GMarker(point, markerOptions); 
    marker.html = 'hello world'; 
    map.addOverlay(marker); 
    GEvent.addListener(marker, "click", function() { 
     marker.openInfoWindowHtml(marker.html); 
    }) 

내가 //markerOptions = { icon:myIcon };

의 주석을 해제하는 경우

내 사진이 표시되었지만 더 이상 마커를 클릭 할 수 없습니다.

누군가 나를 도울 수 있습니까? http://www.roulette-chat.fr/google.php에서 작동하는 것을 볼 수 있습니다.

감사합니다.

+1

당신이 사용되지 않는 API v2를 사용하는 이유. 당신은 v3를 사용할 수 있습니다. – defau1t

답변

1

대신 api v3을 사용합니다. 당신이 사용하고있는 것은 더 이상 사용되지 않습니다. 자신의 이미지를 마커로 사용하려면 다음과 같이 사용할 수 있습니다. 마커를 설정하기 위해 클릭 할 수있는 당신은 당신이이 같은 eventListener을 추가해야하는 작업을 추가하려면, 등록 clickable:true

<script type="text/javascript"> 
     (function() { 
     window.onload = function(){ 
      // Creating a LatLng object containing the coordinate for the center of the map 
      var latlng = new google.maps.LatLng(56.83, 15.16); 
      // Creating an object literal containing the properties we want to pass to the map 
      var options = { 
      zoom: 7, 
      center: latlng, 
      mapTypeId: google.maps.MapTypeId.ROADMAP 
      }; 
      // Calling the constructor, thereby initializing the map 
      var map = new google.maps.Map(document.getElementById('map'), options); 

      var marker = new google.maps.Marker({ 
      position: new google.maps.LatLng(56.8848, 14.7730), 
      map: map, 
      title: 'My workplace', 
      clickable: true, 
      icon: 'url of your image' //this is a custom marker Image 
      }); 
     } 
     })(); 
     </script> 

을 사용할 필요가 :

google.maps.event.addListener(marker, 'click', function() { 
    //do some action 
});