2010-10-26 69 views
1

我想在网页中放置一张地图,用户可以根据需要放置交互式标记(位置引脚)。现在,无论何时放置标记,我都希望存储指定标记的lat,long值以保存在我的服务器(phpmyadmin)中的数据库中。在Google地图中添加交互式标记API

试图开始使用Google地图数据API。已经看过很多例子,但是找不到任何可以放置交互式标记的地方。

回答

1

我要告诉你如何与v3 of the APi

  • 做创建地图......我会假设你有这部分下降。
  • 将一个事件监听器添加到地图。这个事件监听器将调用一个将创建标记的函数(在这种情况下为add_marker)。您可以使用任何您想要的事件,这会使用点击事件。

google.maps.event.addListener(this.map, 'click', add_marker); 

  • 创建添加标记到数据库,然后在地图的功能。这将需要一些AJAX。您可以使用event.latLng得到纬度/经度

function add_marker(event) { 
    lat = event.latLng.lat; 
    lng = event.latLng.lng; 
    // ajax code here that posts the lat/lng to the server 
    // only call the remaining code to add the marker if it was successful 
    var marker = new google.maps.Marker({ 
     position: event.latLng, 
     map: map // put the handle of your map here 
    }); 
} 
+0

非常感谢..! – Pow 2010-10-26 17:32:13

相关问题