0

有没有其他方法可以在不使用函数的情况下获取用户的纬度和经度didUpdateLocations。我只想这样做一次并在加载视图时设置初始区域,而不是每次更新用户位置时。

我知道我可以使用下面的代码获取用户的 Lat 和 Lng,但还有其他选择吗?

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

    var userLocation:CLLocation = locations[0] as CLLocation

    var latitude:CLLocationDegrees = userLocation.coordinate.latitude

    var longitude:CLLocationDegrees = userLocation.coordinate.longitude

    var latDelta:CLLocationDegrees = 0.01

    var lonDelta:CLLocationDegrees = 0.01

    var span:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, lonDelta)

    var location:CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longitude)

    var region:MKCoordinateRegion = MKCoordinateRegionMake(location, span)

    myMap.setRegion(region, animated: true)

}
4

1 回答 1

0

iOS 9 有:CLLocationManager.requestLocation(). 此 API 仅为您的目的而提供 - 一种在不打开连续跟踪的情况下在谨慎时间获取位置的方法。

请参阅此页面以预览其工作原理。

在 iOS 8 及更低版本中,我不知道 API。

于 2015-07-09T21:59:26.493 回答