【问题标题】:Google maps address and map display (exceed limit image)谷歌地图地址和地图显示(超限图片)
【发布时间】:2013-07-20 11:44:09
【问题描述】:

我有以下问题。我在 php 中使用谷歌地图来获取纬度和经度的地址以及该位置的地图快照。

要获取地址,我使用以下代码:

// INITIALIZING CURL
$returnValue = NULL;
$ch = curl_init();

// SERVICE CALL
$url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=".$lat.",".$lon."&sensor=false";

// SETTING PARAMS OF CURL
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

// GETTING AND RESULTING RESULT
$result_part = curl_exec($ch);
$json = json_decode($result_part, TRUE);

我解析得到的 JSON 如下:

// PARSING RESULTS FROM JSON
if (isset($json['results'])) {
    foreach    ($json['results'] as $result_part) {
        foreach ($result_part['address_components'] as $address_component) {
            $types = $address_component['types'];
            // GETTING STREET
            if (in_array('route', $types)) {
                $addr = $address_component['long_name'];
            }
            // GETTING STREET NUMBER
            if (in_array('street_number', $types)) {
                $number = $address_component['long_name'];
            }
            // GETTING COUNTRY
            if (in_array('country', $types)) {
                $country = $address_component['long_name'];
            }
            // GETTING POSTAL CODE
            if (in_array('postal_code', $types)) {
                $postal_code = $address_component['long_name'];
            }
            // GETTING CITY
            if (in_array('locality', $types)) {
                $city = $address_component['long_name'];
            }
        }
    }
}

它工作正常,但有时无法获得地址。看起来请求有些超载,但我不明白为什么,因为我正在编程的网站还不能被其他人访问。

与此相关的其他问题是地图快照。代码如下:

<? echo "<a href = \"https://maps.google.com/maps?q=".$lat.",".$lon."\" target=\"_blank\">" ?>
<? echo "<img src=\"http://maps.googleapis.com/maps/api/staticmap?center=" . $lat . "," . $lon . "&zoom=16&size=200x200&markers=color:blue%7Clabel:I%7C" . $lat . "," . $lon . "&sensor=false\" alt=\"google maps\" width=\"200\" height=\"200\" /></a>" ?>

这也很好,但有时我会得到这样的图像:

我怀疑我超出了限制。

有什么想法吗?谢谢你的回答。

【问题讨论】:

  • `我怀疑我超出了限制。有什么想法吗?`这是在共享网络主机(如 RackSpace)上吗?
  • 不,它不在这样的共享虚拟主机上。它在自己的网络服务器上 - 但这个网络也用于公司的网页。谷歌是否有可能通过一个 IP 控制该公司所有人员的访问?我的意思是连接在该 IP 上的整个用户组
  • 因为请求太多而阻塞了地图服务?
  • 那是certainly possible。您似乎没有使用an API key

标签: php google-maps web map geolocation


【解决方案1】:

正如@geocodezip 所暗示的,这可能是因为没有使用密钥。

也根据反向地理编码文档:

https://developers.google.com/maps/documentation/geocoding/#ReverseGeocoding

注意:反向地理编码是一个估计值。地理编码器将尝试在某个容差范围内找到最近的可寻址位置;如果未找到匹配项,则地理编码器将返回零个结果。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-16
    • 1970-01-01
    • 1970-01-01
    • 2020-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-02
    相关资源
    最近更新 更多