Reputation: 29
how can i get lat-/longitude of an address during an CSV file reading ? reading addresses from a csv and write all lat/lan into csv file.
<?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?
Upvotes: 1
Views: 1622
Reputation: 158
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. You can find the relevant documentation here.
SmartyStreets lets you try out their service for free (up to 250 lookups per month). 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.
There is a handy website plugin you can use, as well as the SmartyStreets JavaScript SDK (which I helped write). Disclosure: I am a software developer at SmartyStreets.
Upvotes: 1