在csv导入期间查找纬度/经度


Latitude/Longitude lookup during a csv-import

如何在PHP的CSV-Import期间获得地址的经度/纬度?我从csv文件中导入地址,并将其保存到mysql表中。在导入过程中,我必须验证地址的纬度/经度,以便将这些信息也保存到表中。

代码:

    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请求失败!HTTP/1.0 400错误请求

谢谢你的帮助/提示。

的问候托马斯。

尝试将urlencode()更改为rawurlencode()