Latitude / longitude search during csv import

How can I get lat / long address during CSV import via PHP? I import addresses from csv and save them in mysql table. During import, I have to check the latitude / longitude of the address in order to save this information in a table.

the 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]: Could not open stream: HTTP request failed! HTTP / 1.0 400 Bad Request in

Thanks for the help / advice.

Regards, Thomas

+4
source share
1 answer

Source: https://habr.com/ru/post/1547071/


All Articles