gpt4 book ai didi

javascript - 得到隆。纬度。对于给定国家/地区的给定邮政编码

转载 作者:行者123 更新时间:2023-12-03 05:10:15 27 4
gpt4 key购买 nike

我对 Google 的地理定位 api 还很陌生...

我使用以下 URL 来检索给定地址的地理位置信息。

http://maps.googleapis.com/maps/api/geocode/json?address=address_value

地址参数可以包含多种信息。我对地址参数值的正确格式的研究总是导致我使用诸如邮政编码,国家/地区之类的格式,但这似乎并不总是按预期工作。

我的问题是:我如何才能始终获取特定国家/地区(例如德国)的信息?

示例:

柏林邮政编码范围是 10115-14199

当我尝试以下操作时 http://maps.googleapis.com/maps/api/geocode/json?address=10115,%20Germany

我得到了正确的信息(位于德国):

{
"results" : [
{
"address_components" : [
{
"long_name" : "10115",
"short_name" : "10115",
"types" : [ "postal_code" ]
},
{
"long_name" : "Mitte",
"short_name" : "Mitte",
"types" : [ "political", "sublocality", "sublocality_level_1" ]
},
{
"long_name" : "Berlin",
"short_name" : "Berlin",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Berlin",
"short_name" : "Berlin",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Deutschland",
"short_name" : "DE",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "10115 Berlin, Deutschland",
...

当我尝试这个时 http://maps.googleapis.com/maps/api/geocode/json?address=10696,%20Germany(这也是德国柏林的现有邮政编码)我得到了美国的地址(其中邮政编码被解释为街道号码)

{
"results" : [
{
"address_components" : [
{
"long_name" : "10696",
"short_name" : "10696",
"types" : [ "street_number" ]
},
{
"long_name" : "Berlin Road",
"short_name" : "Berlin Rd",
"types" : [ "route" ]
},
{
"long_name" : "Berlin Heights",
"short_name" : "Berlin Heights",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Berlin Township",
"short_name" : "Berlin Township",
"types" : [ "administrative_area_level_3", "political" ]
},
{
"long_name" : "Erie County",
"short_name" : "Erie County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Ohio",
"short_name" : "OH",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "USA",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "44814",
"short_name" : "44814",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "10696 Berlin Rd, Berlin Heights, OH 44814, USA",

...

最佳答案

您需要使用诸如

之类的组件
http://maps.googleapis.com/maps/api/geocode/json?address=10696&components=country:DE

关于javascript - 得到隆。纬度。对于给定国家/地区的给定邮政编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41854312/

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