如何从google place detail api获取国家、城市、州名

杰明·潘查尔

我想使用来自 google map webservice api 的地点 id 获取地点详细信息

我使用以下方法调用了 api 网址:https : //maps.googleapis.com/maps/api/place/details/json? placeid = ChIJN1t_tDeuEmsRUsoyG83frY4&key =YOUR_API_KEY

我从谷歌得到这样的回应:

{
"html_attributions" : [],
"result" : {
    "address_components" : [
        {
            "long_name" : "5",
            "short_name" : "5",
            "types" : [ "floor" ]
        },
        {
            "long_name" : "48",
            "short_name" : "48",
            "types" : [ "street_number" ]
        },
        {
            "long_name" : "Pirrama Road",
            "short_name" : "Pirrama Rd",
            "types" : [ "route" ]
        },
        {
            "long_name" : "Pyrmont",
            "short_name" : "Pyrmont",
            "types" : [ "locality", "political" ]
        },
        {
            "long_name" : "Council of the City of Sydney",
            "short_name" : "Sydney",
            "types" : [ "administrative_area_level_2", "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" : "2009",
            "short_name" : "2009",
            "types" : [ "postal_code" ]
        }
    ],
    "adr_address" : "5, \u003cspan class=\"street-address\"\u003e48 Pirrama Rd\u003c/span\u003e, \u003cspan class=\"locality\"\u003ePyrmont\u003c/span\u003e \u003cspan class=\"region\"\u003eNSW\u003c/span\u003e \u003cspan class=\"postal-code\"\u003e2009\u003c/span\u003e, \u003cspan class=\"country-name\"\u003eAustralia\u003c/span\u003e",
    "formatted_address" : "5, 48 Pirrama Rd, Pyrmont NSW 2009, Australia",
    "formatted_phone_number" : "(02) 9374 4000",
    "geometry" : {
        "location" : {
            "lat" : -33.866651,
            "lng" : 151.195827
        },
        "viewport" : {
            "northeast" : {
               "lat" : -33.8653881697085,
               "lng" : 151.1969739802915
            },
            "southwest" : {
               "lat" : -33.86808613029149,
               "lng" : 151.1942760197085
            }
        }
    },
    "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
    "id" : "4f89212bf76dde31f092cfc14d7506555d85b5c7",
    "international_phone_number" : "+61 2 9374 4000",
    "name" : "Google",
    "place_id" : "ChIJN1t_tDeuEmsRUsoyG83frY4",
    "rating" : 4.5,
    "reference" : "CmRSAAAAjiEr2_A4yI-DyqGcfsceTv-IBJXHB5-W3ckmGk9QAYk4USgeV8ihBcGBEK5Z1w4ajRZNVAfSbROiKbbuniq0c9rIq_xqkrf_3HpZzX-pFJuJY3cBtG68LSAHzWXB8UzwEhAx04rgN0_WieYLfVp4K0duGhTU58LFaqwcaex73Kcyy0ghYOQTkg",
    "reviews" : [
        {
            "author_name" : "Robert Ardill",
            "author_url" : "https://www.google.com/maps/contrib/106422854611155436041/reviews",
            "language" : "en",
            "profile_photo_url" : "https://lh3.googleusercontent.com/-T47KxWuAoJU/AAAAAAAAAAI/AAAAAAAAAZo/BDmyI12BZAs/s128-c0x00000000-cc-rp-mo-ba1/photo.jpg",
            "rating" : 5,
            "relative_time_description" : "a month ago",
            "text" : "Awesome offices. Great facilities, location and views. Staff are great hosts",
            "time" : 1491144016
        }
    ],
    "scope" : "GOOGLE",
    "types" : [ "point_of_interest", "establishment" ],
    "url" : "https://maps.google.com/?cid=10281119596374313554",
    "utc_offset" : 600,
    "vicinity" : "5, 48 Pirrama Road, Pyrmont",
    "website" : "https://www.google.com.au/about/careers/locations/sydney/"
},
"status" : "OK"

}

所以请帮我从结果中获取国家和州名

拉克什·贾哈尔

试试这个,你会得到州和国家

$json = json_decode($result);

foreach ($json->results as $result) {
    foreach($result->address_components as $addressPart) {
       if ((in_array('locality', $addressPart->types)) && (in_array('political', $addressPart->types)))
       $city = $addressPart->long_name;
        else if ((in_array('administrative_area_level_1', $addressPart->types)) && (in_array('political', $addressPart->types)))
       $state = $addressPart->long_name;
       else if ((in_array('country', $addressPart->types)) && (in_array('political', $addressPart->types)))
       $country = $addressPart->long_name;
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Google Place Autocomplete API调用入门

来自分类Dev

使用Google Place API获取事件

来自分类Dev

如何获取OSM节点的城市和国家/地区?

来自分类Dev

google place搜寻api和“ Listing by”文字

来自分类Dev

如何请求Google Place API返回地点的ID?

来自分类Dev

解析Google Place API JSON

来自分类Dev

如何获得评论数Google Place API?

来自分类Dev

google place api图标列表

来自分类Dev

如何通过Google JavaScript API获取知道place_id的位置坐标

来自分类Dev

Google Place API在Android中显示错误

来自分类Dev

Google Place API(地方搜索器)

来自分类Dev

如何获取铁轨上所有国家和城市的清单?

来自分类Dev

如何使用照片参考在angularjs中获取Google Place照片

来自分类Dev

如何使用Laravel Eloquent获取相关城市的国家/地区名称

来自分类Dev

如何从iOS的Google Place API获取20个以上的可能性地点

来自分类Dev

google-place-api返回null json

来自分类Dev

如何通过向Google Maps API提供城市来查找相应的国家和地区

来自分类Dev

google place搜寻api和“ Listing by”文字

来自分类Dev

Google Place API限制-非使用限制

来自分类Dev

从google-app-engine获取国家/城市数据

来自分类Dev

如何针对MASTER条目获取最新的DETAIL条目?

来自分类Dev

Google Place Api用于获取地点的自动完成建议

来自分类Dev

使用Objective-C将Google Autocomplete Place Search API限制为特定国家/地区

来自分类Dev

使用Google Maps API从城市获取州和国家的place_id

来自分类Dev

Google Places API针对同一城市返回不同的place_id

来自分类Dev

Google Place API:无法从 google place api android 获取大陆名称

来自分类Dev

动态选择如何获取“特定国家特定国家的特定城市”?

来自分类Dev

如何使用 Google Place API 从指定的经纬度获取地点地址

来自分类Dev

如何从 New Place SDK 中的 autocompletePredictions 中获取 Place 对象

Related 相关文章

  1. 1

    Google Place Autocomplete API调用入门

  2. 2

    使用Google Place API获取事件

  3. 3

    如何获取OSM节点的城市和国家/地区?

  4. 4

    google place搜寻api和“ Listing by”文字

  5. 5

    如何请求Google Place API返回地点的ID?

  6. 6

    解析Google Place API JSON

  7. 7

    如何获得评论数Google Place API?

  8. 8

    google place api图标列表

  9. 9

    如何通过Google JavaScript API获取知道place_id的位置坐标

  10. 10

    Google Place API在Android中显示错误

  11. 11

    Google Place API(地方搜索器)

  12. 12

    如何获取铁轨上所有国家和城市的清单?

  13. 13

    如何使用照片参考在angularjs中获取Google Place照片

  14. 14

    如何使用Laravel Eloquent获取相关城市的国家/地区名称

  15. 15

    如何从iOS的Google Place API获取20个以上的可能性地点

  16. 16

    google-place-api返回null json

  17. 17

    如何通过向Google Maps API提供城市来查找相应的国家和地区

  18. 18

    google place搜寻api和“ Listing by”文字

  19. 19

    Google Place API限制-非使用限制

  20. 20

    从google-app-engine获取国家/城市数据

  21. 21

    如何针对MASTER条目获取最新的DETAIL条目?

  22. 22

    Google Place Api用于获取地点的自动完成建议

  23. 23

    使用Objective-C将Google Autocomplete Place Search API限制为特定国家/地区

  24. 24

    使用Google Maps API从城市获取州和国家的place_id

  25. 25

    Google Places API针对同一城市返回不同的place_id

  26. 26

    Google Place API:无法从 google place api android 获取大陆名称

  27. 27

    动态选择如何获取“特定国家特定国家的特定城市”?

  28. 28

    如何使用 Google Place API 从指定的经纬度获取地点地址

  29. 29

    如何从 New Place SDK 中的 autocompletePredictions 中获取 Place 对象

热门标签

归档