我需要扭转地理codeA十万纬度列表/经度坐标。我能做到这一点的一组坐标没有问题,但是当它涉及到许多人来说,只会做5的时间。我需要弄清楚如何做到这一步,时间的循环,所以它不会被谷歌拒绝。
我在别处被告知,我需要利用回调函数,但我不能确定如何做到这一点。
下面是一些演示code
< HEAD>
< META HTTP-当量=内容类型内容=text / html的;字符集= UTF-8/>
<脚本类型=文/ JavaScript的SRC =JS / jQuery的-1.7.2.min.js>< / SCRIPT>
<脚本类型=文/ JavaScript的SRC =http://maps.google.com/maps/api/js?sensor=false>< / SCRIPT>
<脚本类型=文/ JavaScript的>
VAR地理codeR =新google.maps.Geo codeR();
变种C = [];
C [0] =43.5878,-79.6777;
C [1] =49.2828,-123.1414;
C [2] =49.2895,-123.127;
C [3] =49.2784,-123.1364;
C [4] =49.0327,-122.2529;
C [5] =49.2696,-123.0587;
C [6] =49.269,-122.9954;
C [7] =49.235,-122.882;
C [8] =49.1908,-122.7508;
C [9] =49.085,-122.4111;
变种一个= [];
函数codeLatLng(输入,I){
变种latlngStr = input.split(,,2);
变种纬度= parseFloat(latlngStr [0]);
变种LNG = parseFloat(latlngStr [1]);
VAR经纬度=新google.maps.LatLng(纬度,经度);
地理coder.geo code({
经纬度:经纬度
},功能(结果状态){
A [1] =结果[0] .formatted_address;
$(#考)追加(A [1] +< BR />中)。
});
}
函数此Showmethemoney(){
对于(VAR I = 0; I< = c.length - 1;我++){
$(#考)追加(I +)+ C(I)+< BR />中);
codeLatLng(C [I],I);
};
}
< / SCRIPT>
< /头>
<身体GT;
< DIV ID =测试>< / DIV>
< BR />
<按钮的onclick =此Showmethemoney();>给我钱<!/按钮>
< /身体GT;
我需要的结果是内嵌在自己的坐标。
任何帮助将是很大的AP preciated!
感谢。
编辑:
获取得远一点:
VAR地理codeR =新google.maps.Geo codeR();
变种C = [];
C [0] =43.5878,-79.6777;
C [1] =49.2828,-123.1414;
C [2] =49.2895,-123.127;
C [3] =49.2784,-123.1364;
C [4] =49.0327,-122.2529;
C [5] =49.2696,-123.0587;
C [6] =49.269,-122.9954;
C [7] =49.235,-122.882;
C [8] =49.1908,-122.7508;
C [9] =49.085,-122.4111;
变种一个= [];
函数codeLatLng(输入,I){
变种latlngStr = input.split(,,2);
变种纬度= parseFloat(latlngStr [0]);
变种LNG = parseFloat(latlngStr [1]);
VAR经纬度=新google.maps.LatLng(纬度,经度);
地理coder.geo code({
经纬度:经纬度
},功能(结果状态){
//$("#test").append(results[0].formatted_address +< BR />中);
A [1] =结果[0] .formatted_address;
$(#考)追加(A [1] +< BR />中)。
});
}
变种I = 0;
功能此Showmethemoney(起点,终点){
对于(i =启动; I< = c.length - 1安培;&安培; I<结束;我++){
$(#考)追加(I +)+ C [I] + - );
codeLatLng(C [I],I);
}
如果(ⅰ&GT = c.length - 1){
返回;
}
的setTimeout(函数(){
此Showmethemoney(I,I + 1);
},1500);
}
< / SCRIPT>
< /头>
<身体GT;
< DIV ID =测试>< / DIV>
< BR />
<按钮的onclick =此Showmethemoney(0,1);>给我钱<!/按钮>
< /身体GT;
解决方案
修改功能此Showmethemoney
。通过使用的setTimeout
的jsfiddle 。您可以从10更改间隔任何你想要的数字。
变种i = 0;
功能此Showmethemoney(起点,终点){
对于(i =启动; I< = c.length - 1安培;&安培; I<结束;我++){
$(#考)追加(I +)+ C(I)+< BR />中);
codeLatLng(C [I],I);
}
如果(ⅰ&GT = c.length - 1){
返回;
}
的setTimeout(函数(){
此Showmethemoney(I,I + 5);
},10);
}
此Showmethemoney(I,I + 5);
I need to reverse geocode a list of thousands of latitude/longitude coordinates. I can do this for one set of coordinates no problem, but when it comes to many it will only do 5 at a time. I need to figure out how to do this in one step and time the loop so it will not get denied by google.
I have been told elsewhere that I need to utilize callback functions but I am unsure how to do this.
Here is some demo code
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="js/jquery-1.7.2.min.js" ></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var geocoder = new google.maps.Geocoder();
var c = [];
c[0]="43.5878,-79.6777";
c[1]="49.2828,-123.1414";
c[2]="49.2895,-123.127";
c[3]="49.2784,-123.1364";
c[4]="49.0327,-122.2529";
c[5]="49.2696,-123.0587";
c[6]="49.269,-122.9954";
c[7]="49.235,-122.882";
c[8]="49.1908,-122.7508";
c[9]="49.085,-122.4111";
var a = [];
function codeLatLng(input, i) {
var latlngStr = input.split(",", 2);
var lat = parseFloat(latlngStr[0]);
var lng = parseFloat(latlngStr[1]);
var latlng = new google.maps.LatLng(lat, lng);
geocoder.geocode({
'latLng' : latlng
}, function(results, status) {
a[i] = results[0].formatted_address;
$("#test").append(a[i] + "<br />");
});
}
function showmethemoney(){
for (var i=0; i <= c.length - 1; i++) {
$("#test").append(i + ") " + c[i] + "<br/>");
codeLatLng(c[i], i);
};
}
</script>
</head>
<body>
<div id="test"></div>
<br />
<button onclick="showmethemoney();">Show me the money!</button>
</body>
I need my results to be inline with their coordinates.
Any help would be greatly appreciated!
Thanks.
Edit:
Getting a little bit further:
var geocoder = new google.maps.Geocoder();
var c = [];
c[0]="43.5878,-79.6777";
c[1]="49.2828,-123.1414";
c[2]="49.2895,-123.127";
c[3]="49.2784,-123.1364";
c[4]="49.0327,-122.2529";
c[5]="49.2696,-123.0587";
c[6]="49.269,-122.9954";
c[7]="49.235,-122.882";
c[8]="49.1908,-122.7508";
c[9]="49.085,-122.4111";
var a = [];
function codeLatLng(input, i) {
var latlngStr = input.split(",", 2);
var lat = parseFloat(latlngStr[0]);
var lng = parseFloat(latlngStr[1]);
var latlng = new google.maps.LatLng(lat, lng);
geocoder.geocode({
'latLng' : latlng
}, function(results, status) {
//$("#test").append(results[0].formatted_address + "<br />");
a[i] = results[0].formatted_address;
$("#test").append(a[i] + "<br />");
});
}
var i = 0;
function showmethemoney(start, end) {
for (i = start; i <= c.length - 1 && i < end; i++) {
$("#test").append(i + ") " + c[i] + " - ");
codeLatLng(c[i], i);
}
if( i >= c.length - 1){
return;
}
setTimeout(function(){
showmethemoney(i, i+1);
}, 1500);
}
</script>
</head>
<body>
<div id="test"></div>
<br />
<button onclick="showmethemoney(0, 1);">Show me the money!</button>
</body>
解决方案
Modified function showmethemoney
. by using setTimeout
jsfiddle. You can change interval from 10 to any number you want.
var i = 0;
function showmethemoney(start, end ) {
for (i = start; i <= c.length - 1 && i < end; i++) {
$("#test").append(i + ") " + c[i] + "<br/>");
codeLatLng(c[i], i);
}
if( i >= c.length - 1){
return;
}
setTimeout(function(){
showmethemoney(i, i+5);
}, 10);
}
showmethemoney(i, i+5);