我试图使用以下PHP脚本从地址获取lat和lng值:
$address = "G & D KOI & AQUARIA, KLEINE VELD, DALEN, Nederland";
$prepAddr = str_replace(' ','+',$address);
$prepAddr = str_replace('&','%26',$prepAddr);
$geocode = file_get_contents('https://maps.google.com/maps/api/geocode/json?address='.$prepAddr.'&sensor=false');
$output= json_decode($geocode);
$lat = $output->results[0]->geometry->location->lat;
$lng = $output->results[0]->geometry->location->lng;我要用& %26**.取代还有“和”+。我还需要照顾其他什么吗?**
发布于 2017-02-09 10:18:55
试试这个:
$prepAddr = urlencode($prepAddr);并在API代码中使用$prepAddr,就像您正在使用的那样。
urlencode -URL-编码字符串
string urlencode ( string $str )这个函数在编码要在URL的查询部分中使用的字符串时非常方便,这是将变量传递到下一页的方便方法。
https://stackoverflow.com/questions/42133554
复制相似问题