我有以下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地图不起作用了,请告诉我我到底错过了什么。
发布于 2012-02-13 23:29:26
你已经注释掉了地理编码器,所以在你的if语句中它从来都不是真实的。您还注释掉了对codeLatLng的调用。
首先,试着取消对他们的评论!
更新:
您在信息框中没有包含您期望的ids的元素,地址和消息在哪里?
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 %>呈现给什么?需要引用吗?
https://stackoverflow.com/questions/9262308
复制相似问题