2017-12-31 32 views
1

방향 경로를 다시 그리고 현재 위치로 마커를 옮기고 싶습니다.
현재는 didUpdateLocations 내부에서이 작업을 수행하고 있지만 동시에 여러 마커와 경로를 그리기 때문에 이상하게 보입니다.didUpdateLocations에서 방향 경로 다시 그리기

let location = locations.last 

let destination = CLLocation(latitude: order!.user_coord![0], longitude: order!.user_coord![1]) 

let origin = CLLocation(latitude: (location?.coordinate.latitude)!, longitude: (location?.coordinate.longitude)!) 

self.drawPath(startLocation: origin, endLocation: destination) 

self.createMarker(titleMarker: order!.store_name!, iconMarker: UIImage(named: "icons8-user_filled")!, latitude: order!.user_coord![0], longitude: order!.user_coord![1]) 

self.createMarker(titleMarker: "User", iconMarker: UIImage(named: "icons8-mountain_biking")!, latitude: (location?.coordinate.latitude)!, longitude: (location?.coordinate.longitude)!) 

let camera = GMSCameraPosition.camera(withLatitude: (location?.coordinate.latitude)!, longitude: (location?.coordinate.longitude)!, zoom: 17.0) 
self.map.animate(to: camera) 
locationManager.stopUpdatingLocation() 

답변

0

drawFinished = false 

if(!drawFinished) 
{ 
    drawFinished = true 

    let location = locations.last 

    let destination = CLLocation(latitude: order!.user_coord![0], longitude: order!.user_coord![1]) 

    let origin = CLLocation(latitude: (location?.coordinate.latitude)!, longitude: (location?.coordinate.longitude)!) 

    self.drawPath(startLocation: origin, endLocation: destination) 

    self.createMarker(titleMarker: order!.store_name!, iconMarker: UIImage(named: "icons8-user_filled")!, latitude: order!.user_coord![0], longitude: order!.user_coord![1]) 

    self.createMarker(titleMarker: "User", iconMarker: UIImage(named: "icons8-mountain_biking")!, latitude: (location?.coordinate.latitude)!, longitude: (location?.coordinate.longitude)!) 

    let camera = GMSCameraPosition.camera(withLatitude: (location?.coordinate.latitude)!, longitude: (location?.coordinate.longitude)!, zoom: 17.0) 

    self.map.animate(to: camera) 

    locationManager.stopUpdatingLocation() 

    } 
didUpdate

에있는 viewDidLoad에서 변수

var drawFinished:Bool! 

를 선언 : 여기

내 코드입니다

이 마커와 난 그냥 그것을 시도 업데이트에서 방향 경로를 중지합니다이

func clearMapOverlays() 
    { 
    for dl in self.myMapView.overlays 
    { 

     if(dl is GMSPolyline) 
     { 

      self.myMapView.remove(dl) 

     } 


    } 

    self.myMapView.setNeedsDisplay() 

    for name in self.myMapView.annotations 
    {       

      self.myMapView.removeAnnotation(anno) 

    } 


} 
+0

처럼

drawFinished = false 

명확한 경로와 주석을 설정 업데이트 할 ... 그렇게 할 때 그들은거야 업데이트로 위치가 업데이트되지 않음 –

+0

upate ........ –

+0

mapView.clear()를 사용하여 주석과 맵을 쉽게 지울 수 있지만 거의 매 초마다 지워집니다 –

관련 문제