4
votes

how can i get lat-/longitude of an address during an CSV-Import by PHP? I import addresses from a csv and save these into a mysql-table. During the import i've to verify the latitude/longitude of the adresse to save this information into the table too.

Code:

    while ( ($data = fgetcsv ($handle, 1000, ";")) !== FALSE ) { 
    …

    $adress = urlencode($data[4]).",".$data[5]."+".$data['6'];
    $geocode=file_get_contents("http://maps.google.com/maps/api/geocode/json?address=".$adress."&sensor=false");
    $output= json_decode($geocode);

    $lat = $output->results[0]->geometry->location->lat;
    $lng = $output->results[0]->geometry->location->png;

    …
    }

Error-Info: file_get_contents(http://maps.google.com/maps/api/geocode/json?address=Im+Chr%E4merhoger+10,8910+Affoltern am Albis&sensor=false) [function.file-get-contents.php]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in

Thanks for help/tips.

regards thomas

1
How could anyone ever know? Without a code example, demonstrating what you are doing, it is impossible to answer. I use a lot of importing of lat/lng's from CSV to MySQL myself, but I wouldnt dare to answer without knowing what you are trying to do, precisely.davidkonrad
hi, just added my code...Stiller Eugen
+1, upvoted your question just for that! :)davidkonrad
$lng = $output->results[0]->geometry->location->**png**; ??davidkonrad
Think you must urlencode your request. There is a few blanks that needs to be turned into %20sdavidkonrad

1 Answers