phpを使用してサーバーサイドでジオコードを作成しようとしています。以下は私のコードです:googlemapsを使用したphp serversideジオコーディングではステータスはOKですが、それ以外は返されません
static private function curl_file_get_contents($URL){
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $URL);
$contents = curl_exec($c);
curl_close($c);
if ($contents) return $contents;
else return FALSE;
}
public function preview(Request $request)
{
$url = "https://maps.googleapis.com/maps/api/geocode/json?key=my_api_key&address=1600+Amphitheatre+Parkway,+Mountain+View,+CA";
$resp_json = self::curl_file_get_contents($url);
$resp = json_decode($resp_json, true);
if($resp['status']='OK'){
dd($resp);
}else{
dd('not ok');
}
私はこのステータスをOKにしてdd($ resp)を実行します。実行され、それだけでこの出力を取得します:私はここでは例のJSONレスポンスを見てきました
array:1 [▼
"status" => "OK"
]
を:https://developers.google.com/maps/documentation/geocoding/intro
と返されなければなりませんが、私の場合はそれが返されませんのでもっとたくさんあるはずです。私の場合 :OK、私はここにhttp://erlycoder.com/45/php-server-side-geocoding-with-google-maps-api-v3
編集例をfallowedまし
:私は、その場合には、それがステータスを返すべきではありませんが、それは、私がローカルでこれを実行しているとは何かを持っている可能性があり、なぜ、わかりませんこの過去のブラウザに直接
それはたくさんより多くのデータ
を返します。{
"results" : [
{
"address_components" : [
{
"long_name" : "1600",
"short_name" : "1600",
"types" : [ "street_number" ]
},
{
"long_name" : "Amphitheatre Parkway",
"short_name" : "Amphitheatre Pkwy",
"types" : [ "route" ]
},
{
"long_name" : "Mountain View",
"short_name" : "Mountain View",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Santa Clara County",
"short_name" : "Santa Clara County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "California",
"short_name" : "CA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "USA",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "94043",
"short_name" : "94043",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA",
"geometry" : {
"location" : {
"lat" : 37.4223664,
"lng" : -122.084406
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 37.4237153802915,
"lng" : -122.0830570197085
},
"southwest" : {
"lat" : 37.42101741970851,
"lng" : -122.0857549802915
}
}
},
"place_id" : "ChIJ2eUgeAK6j4ARbn5u_wAGqWA",
"types" : [ "street_address" ]
}
],
"status" : "OK"
}
curlがサポートされていない場合は、上記の出力が生成されません。 –