谷歌地理位置没有采取所有ajax参数作为地址
Google geolocation not taking all ajax parameter for address
我正在创建一个供自己使用的应用程序。此应用程序将在本地机器的电子表格中获取一列地址,并进行ajax调用以将其转换为纬度和经度。我现在遇到的问题是,它不是翻译所有地址,而是只翻译几个地址,每次我重新加载页面并检查时,计数都会有所不同。有些在通过 ajax 请求时返回空值。但是当我手动执行此操作时,它确实可以正确翻译。我这样做是否正确,还是有更好的方法
.PHP
<?php
include 'excel_reader/excel_reader.php'; // include the class
// creates an object instance of the class, and read the excel file data
$excel = new PhpExcelReader;
$excel->read('test.xls');
// Excel file data is stored in $sheets property, an Array of worksheets
/*
The data is stored in 'cells' and the meta-data is stored in an array called 'cellsInfo'
Example (firt_sheet - index 0, second_sheet - index 1, ...):
$sheets[0] --> 'cells' --> row --> column --> Interpreted value
--> 'cellsInfo' --> row --> column --> 'type' (Can be 'date', 'number', or 'unknown')
--> 'raw' (The raw data that Excel stores for that data cell)
*/
// this function creates and returns a HTML table with excel rows and columns data
// Parameter - array with excel worksheet data
function sheetData($sheet) {
$re = '<table>'; // starts html table
$x = 1;
while($x <= $sheet['numRows']) {
$re .= "<tr>'n";
$y = 1;
while($y <= $sheet['numCols']) {
$cell = isset($sheet['cells'][$x][$y]) ? $sheet['cells'][$x][$y] : '';
$re .= " <td class='sheet'>$cell</td>'n";
$y++;
}
$re .= "</tr>'n";
$x++;
}
return $re .'</table>'; // ends and returns the html table
}
$nr_sheets = count($excel->sheets); // gets the number of sheets
$excel_data = ''; // to store the the html tables with data of each sheet
// traverses the number of sheets and sets html table with each sheet data in $excel_data
for($i=0; $i<$nr_sheets; $i++) {
$excel_data .= '<h4>Sheet '. ($i + 1) .' (<em>'. $excel->boundsheets[$i]['name'] .'</em>)</h4>'. sheetData($excel->sheets[$i]) .'<br/>';
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Example PHP Excel Reader</title>
<style type="text/css">
table {
border-collapse: collapse;
}
td {
border: 1px solid black;
padding: 0 0.5em;
}
</style>
</head>
<body>
<?php
// displays tables with excel file data
echo $excel_data;
?>
<div class='lat' style='background-color:#ff0;'></div>
<div class='lon' style='background-color:#0FF;'></div>
</body>
</html>
Ajax 请求:
$(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);
我在node中制作了一个脚本.js并让它运行了300次。如果失败,我记录了 JSON 数据。这是我在失败消息中得到的内容。
{ error_message: 'You have exceeded your rate-limit for this API.',
results: [],
status: 'OVER_QUERY_LIMIT' }
看起来你没事:)
相关文章:
- 函数参数中的数据与指定变量之间的任何性能差异
- 使用Express捕获参数
- 参数变量出现ngTable指令问题
- AngularJS:我可以跳过函数参数回调吗
- 如何使用skip参数使用angular ui引导进行服务器端分页
- 要求未定义JS回调参数
- 我的jQuery插件参数没有正确启动,遇到了问题
- 获取@ResponseBody的一部分作为主干和Spring MVC控制器之间的参数
- 后焦点更改为IE 11中的地址栏,而不是转移到表单中的下一个控件
- jquery设置为使用参数运行
- Javascript”;类“;带有参数的扩展
- 为什么grunt contrib connect的中间件选项的第三个参数是未定义的
- 如何使用URL参数将地址传递到javascript API映射中
- 谷歌地理位置没有采取所有ajax参数作为地址
- 如何在URL中删除参数并在地址栏中显示它,而不会在Javascript中引起重定向
- 客户端重定向使用地址栏参数
- 将参数附加到URL地址在多个函数中不起作用(第二个函数不变)
- 如何解码电子邮件地址的查询参数
- React路由器:无法将电子邮件地址作为参数进行GET
- 在创建 Socket.io 套接字时使用 IP 地址参数