你好,我刚刚开始学习快速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在输出和没有显示我的当前位置在地图上。
Swift代码:
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)
}
}我还将CoreLocation.framawork链接到我的项目中。由于我刚刚开始了解这一点,我没有苹果的开发商执照。
发布于 2016-01-08 16:01:45
无法在模拟器中模拟当前位置。您只能传递坐标,模拟器将在地图中模拟这些坐标。
要模拟自定义位置,请选择模拟器,然后从菜单中选择调试选项,然后选择location,然后选择自定义位置。

并输入您的自定义位置来模拟它:

要启用shouserLocation stting,请转到情节提要,并选择您的地图视图,并在属性检查器中选择shwo用户位置选项。

注意事项:您的当前位置只能显示在真正的设备上。
https://stackoverflow.com/questions/34680926
复制相似问题