地点跟踪器图标未显示在地图上

时间:2017-05-02 23:55:37

标签: ios swift mapkit cllocationmanager

目前我正在设置位置服务,但由于某些奇怪的原因,跟踪器图标未显示: missing tracker icon

我知道它正在工作,因为如果我添加一个引脚,引脚会正确显示: map with pin

我不确定为什么跟踪器没有显示,这是代码:

 @IBOutlet weak var map: MKMapView!

  let locationsManager = CLLocationManager()

  override func viewDidLoad() {
    super.viewDidLoad() 

  locationsManager.delegate = self
    locationsManager.desiredAccuracy = kCLLocationAccuracyBest // sets to best location accuracy
    locationsManager.requestWhenInUseAuthorization()// requests user location when app is opened
    locationsManager.startUpdatingLocation()// updates user location


  }

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

    let userLocation: CLLocation = locations[0]

    let latitude: CLLocationDegrees = userLocation.coordinate.latitude
    let longitude: CLLocationDegrees = userLocation.coordinate.longitude

    let latDelta: CLLocationDegrees = 0.05
    let longDelta: CLLocationDegrees = 0.05

    let span: MKCoordinateSpan = MKCoordinateSpanMake(latDelta, longDelta)
    let location: CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude,longitude)
    let region: MKCoordinateRegion = MKCoordinateRegionMake(location, span)

    map.setRegion(region, animated: true)

    let pin = MKPointAnnotation()
    pin.coordinate.latitude = userLocation.coordinate.latitude
    pin.coordinate.longitude = userLocation.coordinate.longitude
    pin.title = "My current location"
    map.addAnnotation(pin) 
  }

3 个答案:

答案 0 :(得分:1)

您需要将属性ratio = totalMinWatched / videoTiming fraction = ratio - floor(ratio) percentage = 100 * fraction 设置为true。 https://developer.apple.com/reference/mapkit/mkmapview/1452682-showsuserlocation

答案 1 :(得分:1)

MKMapView可以显示用户位置并为您跟踪用户位置:

map.showsUserLocation = true
map.userTrackingMode = .follow

无需实施自己的位置跟踪委托方法。

答案 2 :(得分:-2)

没关系,明白了。在viewDidload()中:

map.showsUserLocation = true