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....
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).loname
empty: you setloname
in the callback ofgeocode()
. This callback is called asynchronously, so you cannot rely onloname
being set after callinglocationplace()
: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...) }
精彩评论