我正在創建一個應用程序,讓用戶可以上傳CSV文件並從每行讀取地址並進行地理編碼。如何使用Bing Maps快速地對CSV文件中的地址進行地理編碼
我最初試圖用google map API來做到這一點。但經過一些研究後,我發現谷歌地圖API有很多限制。例如,你一天只能做2500個查詢,而且每個查詢都需要時間延遲。
這是我到目前爲止已經編寫的代碼:
<script src="http://maps.googleapis.com/maps/api/js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<table width="600">
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post" enctype="multipart/form-data">
<tr>
<td width="20%">Select file</td>
<td width="80%"><input type="file" name="file" id="file" /></td>
</tr>
<tr>
<td>Submit</td>
<td><input type="submit" name="submit" /></td>
</tr>
</form>
</table>
<?php
if (isset($_POST["submit"])) {
if (isset($_FILES["file"])) {
//if there was an error uploading the file
if ($_FILES["file"]["error"] > 0) {
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else {
//Print file details
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"]/1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
$name = $_FILES['file']['name'];
$ext = strtolower(end(explode('.', $_FILES['file']['name'])));
$type = $_FILES['file']['type'];
$tmpName = $_FILES['file']['tmp_name'];
// check the file is a csv
if($ext === 'csv'){
if(($handle = fopen($tmpName, 'r')) !== FALSE) {
// necessary if a large csv file
set_time_limit(0);
$row = 1;
while((($data = fgetcsv($handle, 1000, ',')) !== FALSE) && $row!=10) {
// number of fields in the csv
$col_count = count($data);
$address=implode(",",$data);
$geocode=file_get_contents("http://maps.google.com/maps/api/geocode/json?address=".$address."&sensor=false");
print_r($geocode);
$output= json_decode($geocode);
$lat = $output->results[0]->geometry->location->lat;
$lng = $output->results[0]->geometry->location->lng;
sleep(1);
print_r($address);
echo "------".$lat."----".$lng;
echo "<br/>";
$row++;
}
fclose($handle);
}
}
}
} else {
echo "No file selected <br />";
}
}
?>
我的問題是,我怎麼能做到這一點與Bing地圖API。
下面是一個CSV文件示例:
https://drive.google.com/open?id=0Bx3FBqTEy_0MaHp1QVhiNkVTLU0