在它正常工作之前,我尝试使用 curl 获取带有邮政编码的谷歌地图,但现在它不工作了,它给了我随机的谷歌地图位置。
本网站使用以下代码。
function map_apper($address,$big=""){
$address = str_replace(" ","+",$address);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://maps.googleapis.com/maps/api/geocode/xml?address=".$address."&sensor=true");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$xml = curl_exec($ch);
//Use SimpleXML library to get the data from the XML string
$xml = new SimpleXMLElement($xml);
$lat = $xml->result[0]->geometry[0]->location[0]->lat;
$lng = $xml->result[0]->geometry[0]->location[0]->lng;
$coords = $lat . "," . $lng;
curl_close($ch); //Close the CURL instance, to keep things tidy
$output = "<iframe class=\"google_map\"";
if(!empty($big)){
$output .= "id='big_map'";
}
$output .= " frameborder=\"0\" scrolling=\"yes\" marginheight=\"0\" marginwidth=\"0\" src=\"https://maps.google.com/?q= {$lat},{$lng}&ie=UTF8&z=16&output=embed\"></iframe>";
return $output;
}