0

在它正常工作之前,我尝试使用 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}&amp;ie=UTF8&z=16&output=embed\"></iframe>";   
    return $output;
}
4

1 回答 1

0

在您的请求中使用来自 Web 服务文档的密钥:

所有地理编码 API 应用程序都应使用 API 密钥。在您的请求中包含一个密钥:

允许您在 Google Developers Console 中监控应用程序的 API 使用情况。启用每个密钥而不是每个 IP 地址的配额限制。

确保 Google 可以在必要时就您的申请与您联系。

于 2015-04-07T17:34:19.053 回答