Ios 获取错误的用户位置
你好,我刚刚开始学习swift ios-9。 我使用以下代码来获取用户的当前位置,但它正在获取位置Ios 获取错误的用户位置,ios,swift,Ios,Swift,你好,我刚刚开始学习swift ios-9。 我使用以下代码来获取用户的当前位置,但它正在获取位置 <+37.78583400,-122.40641700> +/- 5.00m (speed -1.00 mps / course -1.00) @ 1/8/16, 3:38:10 PM Greenwich Mean Time 我还将CoreLocation.framawork链接到我的项目。 由于我刚刚开始了解这一点,我没有苹果的开发者许可证。您无法在模拟器中模拟当前位置。您只能传递
<+37.78583400,-122.40641700> +/- 5.00m (speed -1.00 mps / course -1.00) @ 1/8/16, 3:38:10 PM Greenwich Mean Time
我还将CoreLocation.framawork链接到我的项目。
由于我刚刚开始了解这一点,我没有苹果的开发者许可证。您无法在模拟器中模拟当前位置。您只能传递坐标,模拟器将在地图中模拟这些坐标 要模拟自定义位置,请选择模拟器,然后从菜单中选择调试选项,然后选择位置,然后选择自定义位置 并输入自定义位置以模拟它: 要启用shouserLocation测试,请转到情节提要,选择地图视图,并在属性检查器中选择shwo用户位置选项
注意:您的当前位置只能在真实设备上显示。r您在设备或模拟器上测试此功能?您是否已启用显示用户位置设置?我正在模拟器上测试,如何启用用户位置设置?
class ViewController: UIViewController, CLLocationManagerDelegate, MKMapViewDelegate {
@IBOutlet weak var map: MKMapView!
var manager:CLLocationManager!
override func viewDidLoad()
{
super.viewDidLoad()
manager = CLLocationManager()
manager.delegate = self
manager.desiredAccuracy = kCLLocationAccuracyBest
manager.requestWhenInUseAuthorization()
manager.startUpdatingLocation()
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
print(locations[0])
//userLocation - there is no need for casting, because we are now using CLLocation object
let userLocation:CLLocation = locations[0]
let latitude:CLLocationDegrees = userLocation.coordinate.latitude
let longitude:CLLocationDegrees = userLocation.coordinate.longitude
let latDelta:CLLocationDegrees = 0.01
let lonDelta:CLLocationDegrees = 0.01
let span:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, lonDelta)
let location:CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longitude)
let region:MKCoordinateRegion = MKCoordinateRegionMake(location, span)
map.setRegion(region, animated: true)
}
}