gpt4 book ai didi

php - Google Places API 网络服务 (PHP) : how to get 'administrative_area_2 place_id' for a given 'place_id'

转载 作者:可可西里 更新时间:2023-11-01 13:27:50 26 4
gpt4 key购买 nike

我的网络应用收到用户选择的地理区域的 place_id。例如:如果用户在前端选择 place called "Comacchio" (这是一个城镇,administrative_area_level_2 的一部分,称为 Province of Ferrara)我的网络应用程序接收了 Comacchio 的 place_id:ChIJ0yHebbB1fkcR7YujotES0dA

当我在 maps.googleapis.com 上查询 place_id 时,我得到了大量信息(见下文)但不是我需要的信息:我需要的是 administrative_area_level_2 的 place_id输入的 place_id(Provincia di FerraraChIJ7y4rEyxCfkcRwH-6_AubBwM)。

正如您在下面看到的,Provincia di Ferrara 作为字符串返回,但不是我需要的 place_id。

Array (
[html_attributions] => Array(
)

[result] => Array (
[address_components] => Array (
[0] => Array (
[long_name] => Comacchio
[short_name] => Comacchio
[types] => Array (
[0] => locality
[1] => political
)
)

[1] => Array (
[long_name] => Comacchio
[short_name] => Comacchio
[types] => Array (
[0] => administrative_area_level_3
[1] => political
)
)

[2] => Array (
[long_name] => Provincia di Ferrara
[short_name] => FE
[types] => Array (
[0] => administrative_area_level_2
[1] => political
)
)

[3] => Array (
[long_name] => Emilia-Romagna
[short_name] => Emilia-Romagna
[types] => Array (
[0] => administrative_area_level_1
[1] => political
)
)

[4] => Array (
[long_name] => Italy
[short_name] => IT
[types] => Array (
[0] => country
[1] => political
)
)

[5] => Array (
[long_name] => 44022
[short_name] => 44022
[types] => Array (
[0] => postal_code
)
)
)

[adr_address] => <span class="postal-code">I-44022</span> <span class="locality">Comacchio</span> <span class="region">FE</span>, <span class="country-name">Italy</span>
[formatted_address] => 44022 Comacchio FE, Italy
[geometry] => Array (
[location] => Array (
[lat] => 44.6940053
[lng] => 12.1793532
)

[viewport] => Array (
[northeast] => Array (
[lat] => 44.7056942
[lng] => 12.2000628
)

[southwest] => Array (
[lat] => 44.6839703
[lng] => 12.15889
)
)
)

[icon] => http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png
[id] => cb8042e2b729756e683d2aff008871f9876081dd
[name] => Comacchio
[place_id] => ChIJ0yHebbB1fkcR7YujotES0dA
[reference] => CoQBdgAAAGSwypFqE8NNsCqFFroul7U-c8ACswn9Zd_O89SAK6nxPTpsevzOLaa9rQa0-ms2SXDgnrAxKkQ7av8KHxjRHL0UB_GD_xBzMM2u5iYCDVhoLtwSKMifSJAX7T0q9pdqeB6kzPa3IbLGpdDcaMOOAWZ8gf1gtbNjr9Wf3oo5cV4JEhAWQYrsRynoan3_W0DMElMSGhQb2BUPnW0s_cCUgeHkskTZwSPNeg
[scope] => GOOGLE
[types] => Array (
[0] => locality
[1] => political
)

[url] => https://maps.google.com/maps/place?q=44022+Comacchio+FE,+Italy&ftid=0x477e75b06dde21d3:0xd0d112d1a2a38bed
[vicinity] => Comacchio
)

[status] => OK
)

最佳答案

您可以尝试使用所选地点的 administrative_area_level_2(将国家/地区添加到查询参数,以获得更准确的预测)值从 PHP 调用 Google Places API Web 服务,例如:

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Provincia%20di%20Ferrara,%20Italy&types=(regions)&language=pt_BR&key={private_key_removed}

输出应该是:

{
"predictions" : [
{
"description" : "Provincia di Ferrara, Itália",
"id" : "b5fa0282b59be22bd0ad64f97011f744db1aeed8",
"matched_substrings" : [
{
"length" : 20,
"offset" : 0
}
],
"place_id" : "ChIJ7y4rEyxCfkcRwH-6_AubBwM",
"reference" : "CkQ1AAAAqCcMPeJiVWhf2mlBLCJVf82WAxOUARNWqT6NWbp7AEb2nlub1ax3iUMDTKsCAvM_Y6Uylc78mSB_QB5bECVkGxIQxCwIgZ4_WC6fAPJB_N7o0RoU8m_Sdb6CpSyaZeW2lpi9YoJ8bO0",
"terms" : [
{
"offset" : 0,
"value" : "Provincia di Ferrara"
},
{
"offset" : 22,
"value" : "Itália"
}
],
"types" : [ "administrative_area_level_2", "political", "geocode" ]
}
],
"status" : "OK"
}

关于php - Google Places API 网络服务 (PHP) : how to get 'administrative_area_2 place_id' for a given 'place_id' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31598397/

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