简体   繁体   English

reverseGeocodeLocation(_ location: CLLocation) 方法是否在离线模式下工作?

[英]Does reverseGeocodeLocation(_ location: CLLocation) method works in offline mode?

I'm getting a location name from the method reverseGeocodeLocation(_ location: CLLocation) .我从方法reverseGeocodeLocation(_ location: CLLocation)获取位置名称。 My requirement is along with storing Lat-Long values in DB in offline mode, I also want to store this location name string obtained from the above method.我的要求是在离线模式下将 Lat-Long 值存储在 DB 中,我还想存储从上述方法获得的这个位置名称字符串。 This is what I've implemented:这是我已经实现的:

geoCoder.reverseGeocodeLocation(location, completionHandler: { (placemarks, error) in
            
  let place = placemarks?[0]
  var countryName = ""
            
  if let countryString = place?.country {
       countryName = countryString
  }

I can definitely obtain lat-long in offline mode;我绝对可以在离线模式下获得lat-long; my question is, does the above method work in offline mode too?我的问题是,上述方法是否也适用于离线模式

As the documentation says (emphasis added):正如文档所说(强调添加):

This method submits the specified location data to the geocoding server asynchronously and returns.该方法将指定的位置数据异步提交给地理编码服务器并返回。

Since it is sending the request to a server, you almost certainly will not be able to get the reverse geocode response if offline.由于它将请求发送到服务器,因此如果离线,您几乎可以肯定无法获得反向地理编码响应。

But you can add the coordinates to some persistent store, you should be able to reverse geocode them when you are back online.但是您可以将坐标添加到某个持久存储中,当您重新联机时,您应该能够对它们进行反向地理编码。 If you do this, though, remember that they are rate-limited.但是,如果您这样做,请记住它们是有速率限制的。 As the documentation goes on to say:正如文档继续说的那样:

Geocoding requests are rate-limited for each app, so making too many requests in a short period of time may cause some of the requests to fail.每个应用程序的地理编码请求都有速率限制,因此在短时间内发出过多请求可能会导致某些请求失败。 When the maximum rate is exceeded, the geocoder passes an error object with the value CLError.Code.network to your completion handler.当超过最大速率时,地理编码器将带有值CLError.Code.network的错误 object 传递给您的完成处理程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM