2011-07-26 58 views
1



我有一個與Google Maps API相關的問題。我正在學習如何使用Google Maps API。我只能在div標籤中顯示地圖,但我想要的是可以單擊地圖並顯示標記並返回點擊點的LatLng。Google Maps JavaScript API V3 - 要添加標記並返回標記的LatLng

function initialize(v_lat,v_long,v_place) { 
    var latlng = new google.maps.LatLng(-34.397, 150.644); 
    var myOptions = { 
     zoom: 15, 
     center: latlng, 
     mapTypeId: google.maps.MapTypeId.SATELLITE 
    }; 

    var map = new google.maps.Map( document.getElementById("map_canvas")  , myOptions ); 
} 

回答

0

這裏就是你在這一點上的地圖標記的地方點擊,點擊標記將返回該位置的經緯度信息的單擊事件例如

試試這個

var marker; 
google.maps.event.addListener(map, 'click', function() { 
    if(marker==null){ 
     marker = new google.maps.Marker({ 
      position: myLatlng, 
      map: map, 
      title:"Hello World!" 
     }); 
     google.maps.event.addListener(marker, 'click', function() { 
      alert("latlng" + marker.getPosition()); 
     }); 

    } 
}); 

這裏是V3,你可以找到相關地圖

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

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

所有教程的鏈接,谷歌地圖