[英]Reverse Geocoding in Google Maps api 3
我有以下Javascript代碼,並且想對地圖應用反向地址編碼
這是我的JS代碼
更新資料
<script type="text/javascript">
var map;
var geocoder;
var markers = new Array();
function initialize() {
geocoder = new google.maps.Geocoder();
var GPS = <%=GPS %>
var latlng = new google.maps.LatLng(31.2330555556,72.3330555556);
var myOptions = {
zoom: 7,
scaleControl:true,
pancontrol: true,
streetViewControl: true,
center: latlng,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
},
mapTypeId: google.maps.MapTypeId.HYBRID
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var infowindow = new google.maps.InfoWindow();
for(i=0; i<GPS.length; i++)
{
//GeoCoding
if (geocoder) {
geocoder.geocode({'latLng': latlng}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
markers[i] = new google.maps.Marker(
{
position: GPS[i].GPS,
map: map,
draggable:true,
Info: results[1].formatted_address,
title:GPS[i].TITLE
}
}
}
});
google.maps.event.addListener(markers[i], 'click', function() {
infowindow.setContent(this.Info);
infowindow.open(map,this);
});
}
}
</script>
先生,這是我的更新代碼,我曾在其中編寫過反向地理編碼代碼,但現在MU地圖無法正常工作,請告訴我我確實缺少的內容
您已注釋掉地址解析器,因此if語句對您而言永遠不是真的。 您也已注釋掉對codeLatLng的調用。
嘗試取消注釋,對於初學者!
更新:
您在信息框中沒有具有期望ID的元素,地址和消息在哪里?
Info: '<table frame=box><tr>
<td align="Left">
<font face="Arial" size=2 color=#336699>Name:</td>
<td align="Left"><font face="Arial" size=2>'+ GPS[i].TITLE + '</font></td></tr><tr>'+
</td><td align="Left"><font face="Arial" size=2>'+ GPS[i].CNT_TEH + '</font></td></tr>'+
'</table>'
這確實是令人討厭的html ..,但是請確保您有<span id='address'></span>
或div也是一個用於發送消息的人。
還有<%= GPS%>呈現什么? 需要報價嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.