我正在开发一个iOS应用程序,使用该位置在地图上绘制。下面的代码用于创建CLLocationCoordinate2D对象。
let locationData = ["12.9716","77.5946"]
let latitude = NumberFormatter().number(from: locationData[0] as! String)
let longitude = NumberFormatter().number(from: locationData[1] as! String)
print("Latitude Info -> \(String(describing: latitude?.doubleValue))")
print("Longitude Info -> \(String(describing: longitude?.doubleValue))")
let location = CLLocationCoordinate2DMake((latitude?.doubleValue)!, (longitude?.doubleValue)!)该代码在iPhone 6和其他设备上运行良好,但在iPhone 8上,纬度和经度值返回nil。
这种行为很奇怪,因为这种情况发生在特定的设备集上。
该问题已通过使用Double(locationData[0] as! String)解决,但想知道此行为的原因。
发布于 2018-10-31 22:27:19
尝试检查返回nil的iPhone的系统语言和区域设置。
NumberFormatter具有“locale”属性,其默认值为locale.current。
例如:当locale为"en-DE“时,'12.9716‘将返回nil。
https://stackoverflow.com/questions/51646841
复制相似问题