标签: reversegeocodelocation

iOS 13 模拟器:reverseGeocodeLocation - [GEOAddressObject] [NSLocale currentLocale] 对于 NSLocaleCountryCode@ 失败

每当我打电话时:

reverseGeocodeLocation(_ location: CLLocation, preferredLocale locale: Locale?, completionHandler: @escaping CLGeocodeCompletionHandler)
Run Code Online (Sandbox Code Playgroud)

我进入控制台:

[GEOAddressObject] [NSLocale currentLocale] failed for NSLocaleCountryCode@
Run Code Online (Sandbox Code Playgroud)

我在iOS 13 模拟器(iPhone 6s)上得到了这个,所以我不知道这是否也发生在真实设备上。我已经测试了nil和 any Localefor preferredLocale,但它没有任何区别 - 我总是收到失败的消息。

其他任何人都遇到过这种情况并找到了解决方案?

clgeocoder swift reversegeocodelocation

6
推荐指数
1
解决办法
2832
查看次数

使用反向地理位置按距离对列表进行排序

我在iOS9上使用Xcode 7.我想根据用户当前位置到列表中所有其他位置的距离对列表进行升序排序.

我不想通过坐标计算到某个位置的距离,而是通过地址计算,因为距离取决于选择的方法(行驶/步行).我想要做的就是保存每个位置对象中的地址,以便稍后计算到该对象的距离.

使用对象初始化列表时,我在每个对象的初始值设定项中执行此请求:

let location = CLLocation(latitude: latitude, longitude: longitude) //changed!!!

CLGeocoder().reverseGeocodeLocation(location, completionHandler: {(placemarks, error) -> Void in 
    //the code to obtain an address and save it in a location object is here and works
}
Run Code Online (Sandbox Code Playgroud)

我现在的问题是我必须发送172个这样的reverseGeocodeLocation请求,因为我的列表包含172个对象,我需要计算从用户位置到每个对象位置的距离.

如此快速地发送如此多的请求会导致此错误:无法完成操作.(kCLErrorDomain错误2.)

有办法解决这个问题吗?如果事情不明确请告诉我,所以我可以澄清一下

cllocation ios swift ios9 reversegeocodelocation

5
推荐指数
1
解决办法
626
查看次数

CLGeocoder reverseGeocodeLocation返回带有不同纬度/经度的地标吗?(附有游乐场示例)

为什么CLGeocoder reverseGeocodeLocation在查找地址时会返回带有不同纬度/经度的地标?

背景:根据用户在地图上“长按”以放置图钉,但是我的代码反向进行地理编码,以便能够在图钉上放置区域名称,但随后放置的图钉位于其他位置(即良好的用户体验)。因此,我正在寻找一种方法来利用用户实际选择的经度/纬度,但是只需查找位置名称即可。

示例:通过下面的代码,我看到:

  • 输入:-28.7780218895614,152.978574011267
  • 输出:-28.864405,153.0001191

码:

import UIKit
import CoreLocation
import PlaygroundSupport

// Initial Test Co-ordinate
let locInput = CLLocation(latitude: -28.778021889561444, longitude: 152.97857401126666)
print("Input: \(locInput.coordinate.latitude), \(locInput.coordinate.longitude)")

// Initiate Reverse Geocoding
let geocoder: CLGeocoder = CLGeocoder()
print("About to call reverse geocoding function")
geocoder.reverseGeocodeLocation(locInput) { placemarks, error in
    guard let placemarks = placemarks else {fatalError("No Placemarks Provided \(error?.localizedDescription)")}
    for p in placemarks {
        print("OUTPUT:  \(p.location!.coordinate.latitude), \(p.location!.coordinate.longitude)")
    }
}

// Enable Asynch
PlaygroundPage.current.needsIndefiniteExecution = true
Run Code Online (Sandbox Code Playgroud)

mkmapview ios clgeocoder reversegeocodelocation

5
推荐指数
1
解决办法
379
查看次数

SWIFT - LocationManager循环多次?

我有一个locationManager函数来获取用户当前位置并发布城市和州的名称.我有一个打印声明,所以我可以在我的控制台检查一切是否正常工作......就是这样.但是,它打印城市位置3次.这实际上在我的实际应用程序中引起了一个问题,但这超出了这个问题的范围.

我的功能如下:

var usersLocation: String!

var locationManager: CLLocationManager!

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

    let userLocation: CLLocation = locations[0]


    CLGeocoder().reverseGeocodeLocation(userLocation) { (placemarks, error) -> Void in

        if error != nil {

            print(error)

        } else {

            let p = placemarks?.first // ".first" returns the first element in the collection, or nil if its empty
            // this code above will equal the first element in the placemarks array

            let city = p?.locality != nil ? p?.locality : ""
            let state = …
Run Code Online (Sandbox Code Playgroud)

locationmanager ios swift reversegeocodelocation

2
推荐指数
1
解决办法
2121
查看次数