如何在swift3中显示实时跟踪折线?

时间:2017-08-10 16:00:03

标签: ios swift3 annotations mapkit tracking

我想在地图视图中显示实时跟踪。我在单独的阵列中有纬度和经度列表...如何在地图中显示这一点..请任何人帮助这个问题。

func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!)
{
    let location = locations.last as! CLLocation
     let location1 = locations.first as! CLLocation

    // Have to get OldLocation And New Location From API
    let oldCoordinates = location.coordinate
    let newCoordinates = location1.coordinate
    var area = [oldCoordinates, newCoordinates]
    let polyline = MKPolyline(coordinates: &area, count: area.count)
    mapView.add(polyline)

    self.currentCLLocation = CLLocationCoordinate2D(latitude: newCoordinates.latitude, longitude: newCoordinates.longitude)
    let region = MKCoordinateRegion(center: self.currentCLLocation, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))
    self.mapView.setRegion(region, animated: true)

    print("Location Update Details")   
    print(location.coordinate.latitude)
    print(location.coordinate.longitude)
    self.mapView.delegate = self
    let annotation = MKPointAnnotation()
    annotation.coordinate = location1.coordinate
    self.mapView.addAnnotation(annotation)    
}

数组中的值:

Latitudes Array==>>
["12.988415", "12.988445", "12.988492", "12.988558", "12.988673", "12.988788", "12.988903", "12.989039"]
Longitudes Array==>>
["80.218386", "80.21839199999999", "80.218422", "80.218461", "80.218515", "80.218547", "80.21860100000001"]
  1. 如何在位置和位置1变量中循环纬度和经度值?
  2. 每次更新地图时都没有调用DidUpdate方法吗?
  3. 如何根据Lat和Long显示折线?

0 个答案:

没有答案