简体   繁体   English

使用 csv 文件从地址获取纬度和经度

[英]Get Latitude & Longitude From an Address using csv file

how can i get lat-/longitude of an address during an CSV file reading ?如何在读取 CSV 文件期间获取地址的纬度/经度? reading addresses from a csv and write all lat/lan into csv file.从 csv 读取地址并将所有纬度/局域网写入 csv 文件。

<?php
function readCSV($csvFile){
 $file_handle = fopen($csvFile, 'r');
while (!feof($file_handle) ) {
    $line_of_text[] = fgetcsv($file_handle, 1024);
}
fclose($file_handle);
return $line_of_text;
}
$csvFile = 'list1.csv';

$csv = readCSV($csvFile);
?>
<script>
$(document).ready(function() {
var address = <?php echo json_encode($csv); ?>;
var value1 = '';
var csv_data=[];
$.each(address , function(index, val) {
jQuery.ajax({
type: "GET",
dataType: "json",
url: "http://maps.googleapis.com/maps/api/geocode/json",
data: {'address': val[1],'sensor':false},
success: function(data){
    if(data.results.length){
    document.write(val[1]+"==Latitude:"+data.results[0].geometry.location.lat 
   +'==');

document.write("Longitude:"+data.results[0].geometry.location.lng+'<br>');
csv_data.push({"address":val[1],"Latitude":data.results[0].geometry.location.lat,"Longitude":data.results[0].geometry.location.lng});
    }
}
});

});

var csv_data1 = JSON.stringify(csv_data);

$.ajax({  
type: 'POST',  
url: 'res.php', 
data: csv_data1,
success: function(response) {
    console.log(response);
}
});
});
</script>

i have 400000 address are available and need to get all Latitude & Longitude, Any free API?我有 400000 个地址可用,需要获取所有纬度和经度,任何免费的 API?

SmartyStreets has an API that can take a csv file of addresses and give you all sorts of information about them, including Latitude and Longitude. SmartyStreets有一个 API,可以获取地址的 csv 文件,并为您提供有关它们的各种信息,包括纬度和经度。 You can find the relevant documentation here .您可以在此处找到相关文档。

SmartyStreets lets you try out their service for free (up to 250 lookups per month). SmartyStreets 让您免费试用他们的服务(每月最多 250 次查找)。 For your volume of addresses, you naturally would need to buy more lookups.对于您的地址量,您自然需要购买更多的查询。 I don't know of any completely free API that would let you process 400,000 addresses.我不知道有什么完全免费的 API 可以让您处理 400,000 个地址。

There is a handy website plugin you can use, as well as the SmartyStreets JavaScript SDK (which I helped write).您可以使用一个方便的网站插件,以及SmartyStreets JavaScript SDK (我帮助编写)。 Disclosure: I am a software developer at SmartyStreets.披露:我是 SmartyStreets 的软件开发人员。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM