开发者

Reverse geocoding

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 geocode function is below:

function locationplace(latt,lonn)
{
    var rna;
    var llng = new google.maps.LatLng(latt,lonn);
        ligeocoder.geo开发者_StackOverflowcode({'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);
            }
        });


}

My problem is, In line 1 the loname is ""(empty). I try to use setTimeout..but it is not working....i want to display the loname..every time line1 and line 2 executes....

Also I got error: Geocoder failed due to: OVER_QUERY_LIMIT

Please help me....


  1. OVER_QUERY_LIMIT: You call the geocode() function too often. This is handled in other Stackoverflow topics (see 1 and 2 as mentioned in the comment by @OverZealous).

  2. loname empty: you set loname in the callback of geocode(). This callback is called asynchronously, so you cannot rely on loname being set after calling locationplace():

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

    The problem is even amplified when you call locationplace() in a timetout.

    You should use loname in the callback:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜