2012-02-13 109 views
0

我有以下JavaScript代码和我想申请反向地址解析为地图反向地理编码在谷歌地图API 3

这里是我的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地图不工作请告诉我什么是我正在失踪

+0

如果它在一个活动网站上,或者如果你把完整的代码放入类似jsFiddle的东西,那么调试起来更容易,所以我们可以测试它。 – 2012-02-13 19:18:14

+0

同意Mano,你真的需要链接到实时代码。 – andresf 2012-02-15 02:58:32

回答

0

你已经注释过geocoder,所以如果你的陈述从未如此。您还注释了对codeLatLng的调用。

尝试取消注释他们,为初学者!

UPDATE:

你不必与您在信息框期待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%>呈现?它需要被引用的剂量?

+0

兄弟多数民众赞成不是问题我已经尝试取消注释,但所有徒劳请现在告诉我如何显示我的Infowindow Geocoder变量 – user1103342 2012-02-14 03:46:25

+0

我没有元素地址或消息我要直接显示在我的Infowindow Geocoder上标记反对记者coordinate.Please告诉我你可以通过在infowindow上使用地理编码器功能来做到这一点。而且<%= GPS %>是mY服务器端变量,它从数据库获取所有信息来制作标记,也是Infowindow内容 – user1103342 2012-02-15 03:22:54

+0

@ user1103342 GPS是什么看起来像你的服务器已经呈现它之后?你使用铁轨吗?你从哪里得到这段代码?如果你想更新你的infowindow的内容,代码需要更新页面上的元素,你现在正在告诉它更新一个不存在的元素,只要我能够看到你粘贴的元素。我明白你不要那些元素,我告诉你的是,这是问题 – nodrog 2012-02-15 08:12:57