我有這樣的代碼谷歌地圖API和PHP
http://jsfiddle.net/DanielMontenegro/7pdU4/3/
現在,supose,我希望把他們在地圖網站,讓人們通過地理編碼服務報告一些特定的事件。我想問一下,我怎樣才能設法將該事件的地址/座標獲取到一個表中,並且讓用戶彙報到單個數據庫中。
我有這樣的代碼谷歌地圖API和PHP
http://jsfiddle.net/DanielMontenegro/7pdU4/3/
現在,supose,我希望把他們在地圖網站,讓人們通過地理編碼服務報告一些特定的事件。我想問一下,我怎樣才能設法將該事件的地址/座標獲取到一個表中,並且讓用戶彙報到單個數據庫中。
請參閱下面的代碼並試用它。
我使用PHP靜態數組,你可以連接你的數據庫並根據你的需求創建數組。看下面的數組。
<?php $item = array('jaipur, rajasthan,india', 'udaipur, rajasthan,india'); ?>
下面我的代碼看一看。
<html>
<head>
<script src="http://maps.google.com/maps?file=api&v=2&key=AIzaSyDwFjOazEAe1MI7nHV6vUwkWytOp8LH2Zk" type="text/javascript"></script>
</head>
<body onload="initialize();">
<?php $item = array('jaipur, rajasthan,india', 'udaipur, rajasthan,india'); ?>
<script>
var map = null;
var geocoder = null;
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
var addresses = ["<?php echo implode ('","', $item); ?>"]
var geocoder = new GClientGeocoder();
//var addresses = ["A II Z, Ibn Battuta Mall, Sheikh Zayed Road, 5th Interchange, Jebel Ali Village, Dubai","A. Testoni,Dubai Festival City Mall, Ground Floor, Dubai", "Abdulla Hussain Khunji, The Dubai Mall,Downtown, Abu Dhabi"];
var curIndex = 0;
function showAddress() {
var _cur = addresses[curIndex];
geocoder.getLatLng(
_cur,
function(point) {
if (!point) {
//alert(_cur + " not found");
//map.setCenter(new GLatLng(0, 0), 6);
//map.setUIToDefault();
} else {
//console.log(_cur+":"+point);
//alert(_cur);
var cafeIcon = new GIcon(G_DEFAULT_ICON);
// Set up our GMarkerOptions object
markerOptions = { icon:cafeIcon };
map.setCenter(point, 6);
var marker = new GMarker(point, markerOptions);
map.addOverlay(marker);
var sales = new Array();
sales = _cur.split("|");
//Add click event on push pin to open info window on click of the icon
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml("<p class='para1bold' style=\"font-weight: bold;\">Address <br /><span class='para1' style='font-weight:normal;'>" + sales[1] + "</span></p>");
});
//Provides map,satellite,hybrid and terrain views in the map along with zoom control
map.setUIToDefault();
}
//do next after done
curIndex++;
if(curIndex<addresses.length)
showAddress();
}
);
}
showAddress();
}
}
</script>
<div id="map_canvas" style="width:100%; height:750px;"></div>
</body>
</html>
您需要設置某種類型的動作偵聽器(最好是監聽器將偵聽用戶單擊地圖)。然後,只需對產生的經緯度進行地理編碼,然後存儲您在表格中收到的內容。
有一個關於在"Articles" section of the documentation
這一個看起來像它用PHP/MySQL的接口的谷歌地圖API V3很多goood信息回答您的問題; From Info Windows to a Database: Saving User-Added Form Data