0

次の問題があります。PHP で Google マップを使用して、緯度と経度の住所と、この場所の地図のスナップショットを取得しています。

アドレスを取得するには、次のコードを使用します。

// 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>" ?>

これも問題なく機能しますが、次のような画像が得られることがあります。

ここに画像の説明を入力

限界を超えたのではないかと疑っています。

何か案は ?回答ありがとうございます。

4

1 に答える 1