Javascript Google geolocation未将所有ajax参数用作地址
我正在创建一个供自己使用的应用程序。该应用程序将在本地计算机的电子表格中获取一列地址,并调用ajax将其转换为纬度和经度。我现在的问题是,它不是翻译所有的地址,而是只翻译少数地址,每次我重新加载页面并检查时,计数都会变化。有些在通过ajax请求时返回空值。但是,当我手动执行时,它会正确地进行翻译。 我这样做是正确的,还是有更好的方法 PHPJavascript Google geolocation未将所有ajax参数用作地址,javascript,php,jquery,ajax,google-maps,Javascript,Php,Jquery,Ajax,Google Maps,我正在创建一个供自己使用的应用程序。该应用程序将在本地计算机的电子表格中获取一列地址,并调用ajax将其转换为纬度和经度。我现在的问题是,它不是翻译所有的地址,而是只翻译少数地址,每次我重新加载页面并检查时,计数都会变化。有些在通过ajax请求时返回空值。但是,当我手动执行时,它会正确地进行翻译。 我这样做是正确的,还是有更好的方法 PHP 我在node.js中编写了一个脚本,并让它运行了300次。如果失败,我会记录JSON数据。这是我从失败消息中得到的信息 { error_message: '
我在node.js中编写了一个脚本,并让它运行了300次。如果失败,我会记录JSON数据。这是我从失败消息中得到的信息
{ error_message: 'You have exceeded your rate-limit for this API.',
results: [],
status: 'OVER_QUERY_LIMIT' }
看起来你没问题:)这个API有一些使用限制,也许这就是原因。检查失败时返回的内容。我不知道你循环了多少个
td.sheet
元素,但是浏览器也限制了并行请求,也许有些是canceled@A.Wolff,失败时返回null。如果循环失败,则使用常量地址进行测试。如果循环失败,则有时我测试了10束,它返回所有…也许你是对的…它一次翻译有一些限制go@Keren所以,我想你只是达到了API的使用极限。只是想知道,你一行有多少个请求?
$(function(){
$("td.sheet").each(function() {
console.log($(this).text());
var address = $(this).text();
var data;
$.ajax({
type: "POST",
dataType: "json",
url: "test.php?address="+address,
data: data,
success: function(data) {
// console.log(data);
for(var i=0; i< data.length; i++)
{
if($.trim(data[i].latitude)!= ""){
$(".lat").append(data[i].latitude+" => location = "+data[i].location+"<br/>");
}
if($.trim(data[i].longitude)!= ""){
$(".lon").append(data[i].longitude+" => location = "+data[i].location+"<br/>");
}
}
}
});
});
});
$location = $_GET['address'];
//$location="Malaysia 11200";
/*..location coordinate starts*/
$coordinates = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($location) . '&sensor=false');
$coordinates = json_decode($coordinates);
$lat = $coordinates->results[0]->geometry->location->lat;
$lng = $coordinates->results[0]->geometry->location->lng;
$array = array();
array_push($array,array("latitude"=>$lat,"longitude"=>$lng,"location"=>$location));
echo json_encode($array);
{ error_message: 'You have exceeded your rate-limit for this API.',
results: [],
status: 'OVER_QUERY_LIMIT' }