-1

我确实需要退出

street name, postcode, city, state, country , latitude, longitude 从我的地址..

Geocode API 以 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 回答