开发者

Google Maps Geocoder requests

开发者 https://www.devze.com 2023-01-11 21:00 出处:网络
I\'m currently creating an estate agents website with a search which returns a set of properties stored in the database.

I'm currently creating an estate agents website with a search which returns a set of properties stored in the database.

Now I know that google has a limit on how many requests it has per day so I'm trying to think of the best way to do this process.

Basically at the moment, step one of the search is to input a town or postcode with which I was going to send a request to the google ma开发者_运维问答ps api to get the latitude and longitude of these and store them in the database for future use if they weren't already in there.

Do you think this would be ok? Or is there a better solution around this?

Thanks.


Have a look at this site. It worked perfect for me: http://www.geonames.org/export/ws-overview.html

I only used the function "findNearbyStreets" (http://www.geonames.org/maps/us-reverse-geocoder.html#findNearbyStreets), and this was my code:

<?php
$sFile = "list.csv";
$sContent = file_get_contents($sFile);

$aRows  = explode("\n", $sContent);
$sEcho = "";
$i      = 1;

echo "Total rows: " . count($aRows) . "\n===============\n\n";

foreach ($aRows as $sRow)
{
    $aCols  = explode(",", $sRow);

    $sLongitude = $aCols[0];
    $sLatitude = $aCols[1];
    $sInfo = ucfirst($aCols[2]);
    $sInfo = str_replace('"', '', $sInfo);

     $url = "http://ws.geonames.org/findNearbyStreetsOSMJSON?lat=$sLatitude&lng=$sLongitude";
     $json = file_get_contents($url);
     $data = json_decode($json, true);

     $street = $data['streetSegment'][0]['name'];

    $sEcho .= "Some text";

    echo "Done with row: $i/".count($aRows)." \n";
    $i++;
}

$rFile = fopen("newFile.txt", "w+");
fwrite($rFile, $sEcho);
fclose($rFile);
?>

Regards, Paul


Your approach looks OK - the address of a real estate propety won't change too often, I assume ;)

You could even store the per-property coordinates, e.g. "123 Foo Street, Barb AZ is 35.7, -111.0" and only look them up in geocoder if you don't already have them in database.


Just run the code from the user browser -- the API usage count will be count against the user's IP address.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号