gpt4 book ai didi

ios - 检测 mapItemForCurrentLocation 何时无法找到您的设备

转载 作者:行者123 更新时间:2023-12-01 16:30:16 25 4
gpt4 key购买 nike

在获取 map 的当前位置时,我不知道如何测试是否成功。

let source = MKMapItem.mapItemForCurrentLocation()
// returns an object with:
// isCurrentLocation = 1
// name="Unknown location"

我可以测试 source.name == "Unknown location"但这会很糟糕, .

那么......在这种情况下我如何检测失败/零?

最佳答案

像这样的东西?

class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {

@IBOutlet weak var mapView: MKMapView!
var locationManager = CLLocationManager()

在 viewDidLoad 中:
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()

...

代表们
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {

if (!locations.isEmpty)
{

let myLocation = locations[0] as! CLLocation

mapView.setRegion(MKCoordinateRegionMake(CLLocationCoordinate2DMake(myLocation.coordinate.latitude, myLocation.coordinate.longitude),
MKCoordinateSpanMake(0.06, 0.06)), animated: true)
}

}

关于ios - 检测 mapItemForCurrentLocation 何时无法找到您的设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32011758/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com