-1

引き抜く必要があります

street name, postcode, city, state, country , latitude, longitude 私のアドレスから..

Geocode API はこれを Web ブラウザの JSON 形式で返します。使用する最も一般的な形式 (long_name または short_name)

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "City Road",
               "short_name" : "City Rd",
               "types" : [ "route" ]
            },
            {
               "long_name" : "Darlington",
               "short_name" : "Darlington",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "New South Wales",
               "short_name" : "NSW",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Australia",
               "short_name" : "AU",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "2008",
               "short_name" : "2008",
               "types" : [ "postal_code" ]
            }
         ],
         "formatted_address" : "City Road, Darlington NSW 2008, Australia",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : -33.88775940,
                  "lng" : 151.19316880
               },
               "southwest" : {
                  "lat" : -33.8913630,
                  "lng" : 151.18843910
               }
            },
            "location" : {
               "lat" : -33.88924140,
               "lng" : 151.19051430
            },
            "location_type" : "GEOMETRIC_CENTER",
            "viewport" : {
               "northeast" : {
                  "lat" : -33.88775940,
                  "lng" : 151.19316880
               },
               "southwest" : {
                  "lat" : -33.8913630,
                  "lng" : 151.18843910
               }
            }
         },
         "types" : [ "route" ]
      }
   ],
   "status" : "OK"
}

これは私のコードです

$address = urlencode($address);
$googleApi = 'http://maps.googleapis.com/maps/api/geocode/json?address=%s&sensor=false';
$json = file_get_contents(sprintf($googleApi, $address));
$resultObject = json_decode($json);
$address = $resultObject->results[0]->address_components;

// please help me in pulling other data

$location = $resultObject->results[0]->geometry->location;
$latitude = $location->lat;
$longitude = $location->lng;

// (latitude and longitude is working)
4

1 に答える 1

0
    $location = $resultObject->results[0]->address_components[0];
    $long_name  =  $location->long_name;// long_name not ong_name
    $short_name = $location->short_name;
于 2013-06-04T09:32:36.997 に答える