GoogleMaps API(PHP / curl)返回ZERO_RESULT

时间:2017-04-19 07:42:15

标签: php json google-maps curl

我遇到了GoogleMaps API的奇怪问题。

在浏览器中调用以下网址,一切正常。 https://maps.googleapis.com/maps/api/geocode/json?components=country:DE|postal_code:81823&key=[mykey]

但是在PHP中使用相同的url和curl我得到一个ZERO_RESULT?

调用https://maps.googleapis.com/maps/api/geocode/json?components=country:DE|postal_code:90471它在PHP和浏览器中运行良好。

我的PHP代码:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:mapbox="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".examples.MapViewActivity">

    <!-- Set the starting camera position and map style using xml-->
    <com.mapbox.mapboxsdk.maps.MapView
        android:id="@+id/mapView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        mapbox:mapbox_cameraTargetLat="40.73581"
        mapbox:mapbox_cameraTargetLng="-73.99155"
        mapbox:mapbox_styleUrl="@string/mapbox_style_mapbox_streets"
        mapbox:mapbox_cameraZoom="11"/>

</RelativeLayout>

返回第一个网址

$timeout    = 5;
$ch         = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout );
$decode     = json_decode( curl_exec( $ch ) );

curl_close( $ch );
print_r($decode);

0 个答案:

没有答案