我想知道是否有人能夠幫助我請。反向地理編碼在谷歌地圖api v3
我使用下面顯示的代碼來正確繪製從Google Map上的MySQL數據庫中檢索到的標記。
<script type="text/javascript">
//Sample code written by August Li
var icon = new google.maps.MarkerImage("images/location-marker-2.png")
new google.maps.Point(16, 32);
var center = null;
var map = null;
var bounds = new google.maps.LatLngBounds();
function addMarker(lat, lng, info) {
var pt = new google.maps.LatLng(lat, lng);
bounds.extend(pt);
var marker = new google.maps.Marker({
position: pt,
icon: icon,
map: map
});
}
function initMap() {
map = new google.maps.Map(document.getElementById("gmaps-canvas"), {
center: new google.maps.LatLng(0, 0),
zoom: 6,
scrollwheel: true,
draggable: true,
mapTypeId: google.maps.MapTypeId.SATELLITE
});
<?php
include("admin/link.php");
include("admin/opendb.php");
$query = mysql_query("SELECT * FROM `detectinglocations` WHERE `locationid` = '$lid'");
while ($row = mysql_fetch_array($query)){
$locationname=$row['locationname'];
$osgb36lat=$row['osgb36lat'];
$osgb36lon=$row['osgb36lon'];
echo ("addMarker($osgb36lat, $osgb36lon,'<b>$locationname</b><br/>');\n");
}
mysql_close($connect);
?>
center = bounds.getCenter();
map.fitBounds(bounds);
}
</script>
什麼我現在要做的是進一步增加功能,使用戶能夠同時在地圖上點擊使用預先存在的標記從數據庫中作爲一個點,從工作到繪製新的標誌物,在本質上,執行reverse geocode
。
我一直在研究這個問題,現在已經嘗試了很多教程,但我似乎無法使這兩個功能的部分工作。
我知道,讓一個on-click
事件,我需要的線沿線的東西包括:
google.maps.event.addListener(map, 'click', function(event) { marker.setPosition(event.latLng) geocode_lookup('latLng', event.latLng ); }); }
但我必須承認我有點不確定還有什麼我需要合併。
我只是想知道是否有人能夠看看這個請,如果有人能告訴我我出錯的地方,我將非常感激。
許多的感謝和親切的問候
我不太清楚。您希望獲取從數據庫添加的每個標記的地址?或者當地圖被點擊時?當點擊數據庫標記時?上述所有的?反向地理編碼之後,地址應該去哪裏? –
嗨@HeitorChang,感謝您抽出寶貴時間回覆我的博文,以及我對不明確的道歉。加載地圖時,地圖上已經有一個標記。這從存儲在MySQL數據庫中的lat和lng加載。我現在需要做的就是添加這樣的功能,即用戶也可以點擊地圖並執行「反向地理編碼」,而不會影響預先填充的標記。我希望這可以讓它更清楚一些。親切的問候 – IRHM