gpt4 book ai didi

json - Google 放置 API 层次结构 - 街区/郊区 -> 城市 -> 地区 -> 国家

转载 作者:行者123 更新时间:2023-12-03 22:36:37 25 4
gpt4 key购买 nike

问题 -
人们根据自己的兴趣在不同的地方发帖,而其他人则在更大的领域搜索帖子。
例如- 用户 A 在悉尼郊区邦迪海滩 (Bondi Beach) 下发帖。
用户 B 在悉尼下搜索帖子。
预期结果 - 用户 B 可以看到用户 A 的帖子,因为 Bondi 位于悉尼内。
解决方案:
在 Google 位置 API 中查找它告诉您郊区 X 属于城市 Y 等等。
在我的例子中 - 我想获得关于邦迪的信息,告诉我它属于哪个城市。
这是我对邦迪海滩的简单查询(我使用自动完成,因为它是一个自动完成下拉菜单):
https://maps.googleapis.com/maps/api/place/autocomplete/json?sensor=true&input=bondi%20beach&key=myKey

{
"predictions" : [
{
"description" : "Bondi Beach, New South Wales, Australia",
"id" : "ffa6ad484d2fec594378fb2a24e8328a2bc4459f",
"matched_substrings" : [
{
"length" : 11,
"offset" : 0
}
],
"place_id" : "ChIJWTi8xgGyEmsRgK0yFmh9AQU",
"reference" : "CkQ_AAAAMnfwZeK5SV6uPBnPr34JVdHudAGxMtna--JWHtwe7t81gLBGgsB6mRgmj375m7KReRhpMq1Y6AYxCrC2MnYn8hIQQfASvoG5-7LwRcVR7ELjNxoURh-iBs6M2dmrU8wLKIPcFFgymn4",
"terms" : [
{
"offset" : 0,
"value" : "Bondi Beach"
},
{
"offset" : 13,
"value" : "New South Wales"
},
{
"offset" : 30,
"value" : "Australia"
}
],
"types" : [ "locality", "political", "geocode" ]
},
{
"description" : "Bondi Beachouse YHA, Fletcher Street, Bondi Beach, New South Wales, Australia",
"id" : "fdab345a9db5c6cfcddd7cd561a8b83acc538d73",
"matched_substrings" : [
{
"length" : 11,
"offset" : 0
}
],
"place_id" : "ChIJzwpdVYStEmsRd6F0Wa1NQ2I",
"reference" : "CmRbAAAA_AFGY8xaYlQebohzYWKrvNoMiJAktObvU4Vb03ORpmf7-ZTlv3BkU3dJPdAIBMtgol8ngdxC1NhVZA7AsAnkRfe4WPT7GJlqkIa_S0Hsb87Dlt-OT1Dt5uQNg_ei4cRPEhCvI7pwL5qD1US6yrOxvVpXGhRQxfEObV1zUxys2a2EZTkbKUdMbg",
"terms" : [
{
"offset" : 0,
"value" : "Bondi Beachouse YHA"
},
{
"offset" : 21,
"value" : "Fletcher Street"
},
{
"offset" : 38,
"value" : "Bondi Beach"
},
{
"offset" : 51,
"value" : "New South Wales"
},
{
"offset" : 68,
"value" : "Australia"
}
],
"types" : [ "establishment" ]
},
{
"description" : "Bondi Beach Car Park, Campbell Parade, Bondi Beach, New South Wales, Australia",
"id" : "ba6c34f150f7f3ac035d731662f2a08a22a3b5dd",
"matched_substrings" : [
{
"length" : 11,
"offset" : 0
}
],
"place_id" : "ChIJXch67J6tEmsRFXD11Ce64WA",
"reference" : "CmRcAAAA_H6cxlTUVW2JHFb5EO0MQAL-d1M-_6_DXOQAvw6xJOFSri4HaIvodY6lcZH3F8rrAlyaXqOM4lcgbegqvVEPScyRE20iiJSXC6jHPxH5EwplZGPWx7rxy34l1uweXgmhEhBirrakiRpK-Zd_naBW7Hd8GhTiujZAiOEDsWj9tuP3bumLR6SamQ",
"terms" : [
{
"offset" : 0,
"value" : "Bondi Beach Car Park"
},
{
"offset" : 22,
"value" : "Campbell Parade"
},
{
"offset" : 39,
"value" : "Bondi Beach"
},
{
"offset" : 52,
"value" : "New South Wales"
},
{
"offset" : 69,
"value" : "Australia"
}
],
"types" : [ "establishment" ]
},
{
"description" : "Bondi Beach Public School, Campbell Parade, Bondi Beach, New South Wales, Australia",
"id" : "e808bb9453705761b5b1672065a5aaa5b1b5b52a",
"matched_substrings" : [
{
"length" : 11,
"offset" : 0
}
],
"place_id" : "ChIJaXfeKJ6tEmsRM_pgTjpurLs",
"reference" : "CnRiAAAAN-CRd33lyhCZBryEwtPxVdxweAC-WcxikMSlmiP83st3Eu0qt5tOdx_Kxvfb6aTH_F3szZETbrRYSXb8-Ql-NSdXFhIeZjIf3au9qrwIII7y9-ZhFRImHCeYRJ1xslrS2dal0_lulOh_dY39jgofrRIQoVco7kZBb4DgSaACK9h4ARoUf98GpsdtuHPVY615rIszSUVqRpM",
"terms" : [
{
"offset" : 0,
"value" : "Bondi Beach Public School"
},
{
"offset" : 27,
"value" : "Campbell Parade"
},
{
"offset" : 44,
"value" : "Bondi Beach"
},
{
"offset" : 57,
"value" : "New South Wales"
},
{
"offset" : 74,
"value" : "Australia"
}
],
"types" : [ "establishment" ]
},
{
"description" : "Bondi Beach View, Campbell Parade, Sydney, New South Wales, Australia",
"id" : "16758032a0384967c04985914cd861dc2c488fe8",
"matched_substrings" : [
{
"length" : 11,
"offset" : 0
}
],
"place_id" : "ChIJr6fcCputEmsRtFcOcREuc48",
"reference" : "CmRUAAAAK3dQSHexE9SerblRCR84jdJ8ScqqDwteRMH2H1f_uCRVQNVsFmgELlMlWWCG2mMbbNOL0yQRv2K0Bx2aqKIe3Bt236LvDl5sxjDaRvdd7QTdBATMJsTHec-xXc3z9c02EhC-JDoD5ln1Q-qdeb-urugLGhSur_7TThy4ekl9yoXRFzZwZmn26w",
"terms" : [
{
"offset" : 0,
"value" : "Bondi Beach View"
},
{
"offset" : 18,
"value" : "Campbell Parade"
},
{
"offset" : 35,
"value" : "Sydney"
},
{
"offset" : 43,
"value" : "New South Wales"
},
{
"offset" : 60,
"value" : "Australia"
}
],
"types" : [ "establishment" ]
}
],
"status" : "OK"
}
如您所见,唯一告诉我邦迪是悉尼一部分的结果是“邦迪海滩景观”,这没有任何意义,也无助于解决我的问题。
我在世界各地的许多其他地方都遇到过这个问题。
如何获得地点层次结构的准确信息?

最佳答案

我有类似的问题。我做了一些研究,但没有找到准确的解决方案。目前我正在使用以下解决方法,这对我的情况来说已经足够了。

首先,获取一个地点的坐标(place_id 你可以在自动完成结果中找到):

https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJWTi8xgGyEmsRgK0yFmh9AQU&key=yourKey

之后,使用这些坐标和所需的 result_types 执行反向地理编码请求: country, administrative_area_level_1, administrative_area_level_2, locality .

例如:
https://maps.googleapis.com/maps/api/geocode/json?latlng=-33.8914755,151.2766845&result_type=locality&key=yourKey

这不是 100% 准确的方法。它为某些位置提供了多个结果(如您所见,邦迪海滩就是其中之一),但您可以尝试通过其他一些属性选择一个(在这种情况下, colloquial_area 类型的结果是正确的) .

我希望,我的回答至少能对你有所帮助。

关于json - Google 放置 API 层次结构 - 街区/郊区 -> 城市 -> 地区 -> 国家,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25432515/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com