【问题标题】:finding user current location using Google Maps API (Google Places)使用 Google Maps API(Google Places)查找用户当前位置
【发布时间】:2013-07-21 14:17:16
【问题描述】:

我想通过 Google 了解用户的当前位置。我知道如何使用 mapKit 获取用户的高度和经度,但我不知道如何将其翻译为位置或地址(街道名称、城市、国家/地区)。我进行了一些搜索,发现只是使用 NSURL 来访问访问 Google Places 的给定链接。但是,可用的方法是列出用户附近的地点。那么如何知道用户的当前位置呢? 注意:我没有使用 Apple 的地图,因为我的国家不包括在内,而且 Google 更支持它。

【问题讨论】:

    标签: ios objective-c google-maps


    【解决方案1】:

    您可以使用反向地理编码服务。

    这里是文档:

    https://developers.google.com/maps/documentation/geocoding/?hl=en#ReverseGeocoding

    示例请求(JSON):

    http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=false
    

    在 iOS 上获取 JSON 数据:

    Not getting json response in google query of longitude and latitude in iOS?

    对于在 iOS 中解析 JSON 对象,这个答案可能对你有用:

    How to parse specific googlemaps API webservices JSON repsonse

    【讨论】:

    • 好的,我创建了 NSURL 并获得了纬度和经度,我该如何从这里继续?如何下载 JSON 文件并从中提取地址?我不擅长使用 JSON 文件。感谢您的回复顺便说一句
    • 您推荐的帖子非常有用,但他们认为您有 JSON 文件。实际上我不知道如何先下载它。有什么提示吗?
    【解决方案2】:

    没有理由使用 Web API,iOS SDK 已经使用 GMSGeocoder 类处理了这个问题。以下是 Swift 中如何将用户当前位置转换为地址的示例:

    let geocoder = GMSGeocoder()
    geocoder.reverseGeocodeCoordinate(currentLocation.coordinate) { (response, error) -> Void in
    
            print("Response: \(response.firstResult())")
            print("Error: \(error)")
    
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多