我是新来的应用程序开发,我试图让用户位置来模拟器,但我不断得到使用未解决的标识符错误。我看过其他问题,这些问题对于他们自己的项目非常具体,并试图以类似的方式来处理我自己的应用程序,但无济于事。任何帮助,por支持?这里是我的代码,并链接到Xcode的屏幕截图。用户位置不会出现在模拟器在Xcode
import UIKit
import MapKit
import CoreLocation
class SecondViewController: UIViewController, CLLocationManagerDelegate {
//Map
@IBOutlet weak var map: MKMapView!
let manager = CLLocationManager()
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{ let location = locations[0]
let span:MKCoordinateSpan = MKCoordinateSpanMake(0.01, 0.01)
let myLocation:CLLocationCoordinate2D = CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude)
let region:MKCoordinateRegion = MKCoordinateRegionMake(myLocation, span)
self.map.showsUserLocation = true
}
override func viewDidLoad()
{
super.viewDidLoad()
manager.delegate = self
manager.desiredAccuracy = kCLLocationAccuracyBest
manager.requestWhenInUseAuthorization()
manager.startUpdatingLocation()
//This is where I get an error
map.setRegion(region, animated: true)**
}
Error: Use of unresolved identifier
你需要在xcode中的userLocation –
你有没有在模拟器中设置自定义位置? 如果没有调试 - >位置 - >自定义位置 设置并尝试此设置 设置位置之前的设备。所以你需要在经过设备采取的纬度经过之后设置 –