I'm creating an application that lets a user to upload a CSV file and have an address read from each line and geocoded.
I originally tried to do this with the google map API. But after some research i found that the google map api has a lot of limitation. For example, you can do only 2500 query in a day and also per query you need a time delay.
This is the code I've written so far:
<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 />";
}
}
?>
My question is, how can I do this with the Bing Maps API.
Here is a sample CSV file:
https://drive.google.com/open?id=0Bx3FBqTEy_0MaHp1QVhiNkVTLU0