2011-08-02 86 views
0
setTimeout("locationplace("+latt+",+"+lonn+")",2000); //line 1 
document.write("<tr><td>"+(lc+1) + "</td><td>"+sstime+"</td><td>"+ct+"</td><td>"+minsec+"</td><td><a href='#'>"+loname+"</a></td></tr>"); //line 2 

AndReverse地理编码函数是如下:反向地理编码

function locationplace(latt,lonn) 
{ 
    var rna; 
    var llng = new google.maps.LatLng(latt,lonn); 
     ligeocoder.geocode({'latLng': llng}, function(results, status) 
     { 

      if (status == google.maps.GeocoderStatus.OK) 
      { 

       if (results[0]) 
       { 
       loname=results[0].formatted_address; 
       } 
       else 
       { 

       } 
      } 
      else 
      { 
       alert("Geocoder failed due to: " + status); 
      } 
     }); 


} 

我的问题是,在线1loname是 “”(空)。我尝试使用setTimeout..but它不工作....我想显示loname ..every时间一号线和2个线执行....

还有我得到错误:地理编码器失败,由于于:OVER_QUERY_LIMIT

请帮我....

+0

重复:http://stackoverflow.com/questions/3529746/over-query-limit-while-using-google-maps – OverZealous

+0

@ ram:我的回答是否有用? – Jiri

回答

1
  1. OVER_QUERY_LIMIT:您调用geocode()功能过于频繁。这是在其他Stackoverflow主题中处理的(请参阅在@OverZealous的评论中提到的12)。

  2. loname空:您在geocode()的回调中设置了loname。此回调异步调用,所以你不能依靠loname调用locationplace()后被设置:当你在timetout调用locationplace()

    locationplace(...); // calls geocode(), which sets loname asynchronously 
    document.write(...loname...) // CANNOT USE HERE 
    

    问题甚至放大。

    你应该在回调使用loname

    if (results[0]) {      
        loname=results[0].formatted_address; 
        // use loname here: 
        document.write(...loname...) 
    }