ios - Google places api 应该只返回地址

标签 ios iphone google-maps google-maps-api-3

我使用此 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/

相关文章:

ios - Swift 错误 - 使用未解析的标识符 'kGMSMarkerAnimationPop'

ios - 使用 Parse 从预定义的 User 类查询 PFFile

html - 我的图标在桌面和开发工具上看起来不错,但在 iPhone 上就被弄脏了

iphone - 如果我安装 iPhone 操作系统的 SDK 4.0,我仍然能够创建非 4.0 iPad 应用程序吗?

ios - Xcode 模拟器卡在 "Launching Simulator"并在 Xcode 项目中卡住加载

jquery - 谷歌地图未以 fancybox 为中心

ios - 已加载 Nib 但未设置 View 导出 - UITableViewController

ios - AFNetworking 如何检测是否所有文件都已加载

iOS:如果未安装应用程序,Apple Universal Link continueUserActivity 方法不会调用?

google-maps - Google map [API] View 在我的移动设备上显示为灰色