问题
Requirement : I am currently working on an app that has over 30000 records. The requirement is to have location based/aware searching. For eg. within 5mi from my present location.
How will this service be accessed : This service will be accessed from both web and iOS app.
Development platforms :
- Web : Cakephp, php and python
- DB : MySql
- iOS : objective-c
- External libraries currently being used : Google Maps Javascript Api v3
Location based searching
I have been doing some research on this subject, and I will be employing Haversine Formula for this. But for Haversine formula to be effective, I need to have reverse geo code for all my records in my DB. The only reverse geocoding service I have ever used is from Google, and I know for a fact that they don't allow this without displaying the results on their map.
Note: the Geocoding API may only be used in conjunction with a Google map; geocoding results without displaying them on a map is prohibited.
- Are there other APIs or services I can use to reverse geo code all those records ?
- 30000 is a large number. I will obviously be employing cron job for this over a period of time, but as this request will be from same IP, can this be an issue ?
Any help on this will be highly appreciated.
Update 1 #
I found this SO question which recommends OpenStreetMap Nominatim
回答1:
There are all kinds of geocoding services you can use, but you'll most likely have to pay. Check out Cloudmate. They might work out for your situation. If this is a business venture it might be better to spend a little bit of money and make sure you get good data.
30,000 records wont take that long at all. If there's no rate limit it should be able to be done in 10 - 20 minutes. I've geocoded 2000 records one page at a time(100 on each page) and it took 5 minutes.
A while back I built a locations administration interface. It's not finished and the code is not the greatest but it may give you a starting point. It uses google to geocode but can easily be swapped out for any other service.
http://galengrover.com/projects/Store-Locator-Admin/
https://github.com/galen/Store-Locator-Admin
回答2:
$result = mysql_query("SELECT * FROM abc ORDER BY id DESC ") or die(mysql_error());
while($row = mysql_fetch_array( $result )){
$lat=$row['latitude'];
$long=$row['longitude'];
$url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=".$lat.",".$long."&sensor=false";
$json = @file_get_contents($url);
$data = json_decode($json);
$status = $data->status;
$address = '';
if($status == "OK")
{
$address = $data->results[0]->formatted_address;
}
else
{
echo "No Data Found Try Again";
}
mysql_query("UPDATE abc SET location='$address' WHERE id=".$row['id']."") or die(mysql_error());
printf( $address."%d\n", mysql_affected_rows());
echo "<br/><br/>";
}
来源:https://stackoverflow.com/questions/15323166/how-to-prepare-existing-database-for-location-aware-searching