我使用此 url 通过 Get 请求获取地址:https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Nov&key=MyKet&types=address
但有时我只得到没有房子的街道,有时我什至得到城市(如果俄语中的 input=Minsk:https://maps.googleapis.com/maps/api/place/autocomplete/json?input=%D0%9C%D0%98%D0%9D%D0%A1%D0%9A&key=MyKey&types=address)
但是我只想得到有房子的街道,因为我正在编写出租车应用程序并且我只需要完整的地址,如果用户只选择街道是不够的。
因此,如果我从 Google Proletarsk street 25, Bern, Switzerland
- 没问题,但如果我从 Google Proletarsk street, Bern, Switzerland
- 就不行了.
当我从谷歌得到街道和地址的回复时,它总是返回相同的类型
types = (
route,
geocode
);
所以我什至无法区分返回值是街道还是完整地址。
你能给我什么建议吗?
最佳答案
根据您描述的用例,听起来您使用了错误的 API。
你应该使用 the Geocoding API如果您有地址并且希望 Google map 为您解析它并返回额外信息。您可以确定结果是否包含 street_number
,以便判断结果是否包含完整地址。例如:
https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA
会给你这样的结果:
{
"results" : [
{
"address_components" : [
{
"long_name" : "1600",
"short_name" : "1600",
"types" : [ "street_number" ]
},
{
"long_name" : "Amphitheatre Parkway",
"short_name" : "Amphitheatre Pkwy",
"types" : [ "route" ]
},
{
"long_name" : "Mountain View",
"short_name" : "Mountain View",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Santa Clara County",
"short_name" : "Santa Clara County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "California",
"short_name" : "CA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "94043",
"short_name" : "94043",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "1600 Amphitheatre Parkway, Mountain View, CA 94043, USA",
"geometry" : {
"location" : {
"lat" : 37.4223455,
"lng" : -122.0841893
},
"location_type" : "ROOFTOP",
"viewp.....
它给你一个 street_number
,所以你可以告诉它是一个完整的地址。
关于ios - Google places api 应该只返回地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31161047/