3

I'm working on a project in which I need to move my GMSMarker on map like uber app does. The problem I'm facing on crossroads were I need to change the heading as well as bearing(rotation) at the end of road.

I want my marker should move like:

  1. Car first move P1 to vertex point(meeting point)
  2. Then it'll turn towards point P2 and
  3. Finally will move form meeting point to P2

enter image description here

I'm using following line of code for moving marker from location P1 to P2 but it's giving direct distance(purple path). How can I find intermediate coordinate i.e. meeting point as well as the distance from P1 to vertex(meeting point) where I need to turn the car marker in the direction of P2

self.Last_Location = last locaiton of car (P1)
self.Current_Location = current location of car (P2)

and I'm getting location update in every "6 seconds"

func animateCarMovementonMapWithMarker() {
    let bearing: Double = self.getHeadingForDirectionFromCoordinate(Last_Location, toCoordinate: Current_Location)
    let p1: MKMapPoint = MKMapPointForCoordinate(self.Last_Location)
    let p2: MKMapPoint = MKMapPointForCoordinate(self.Current_Location)
    let dist: CLLocationDistance = MKMetersBetweenMapPoints(p1, p2)
    CATransaction.begin()
    CATransaction.setAnimationDuration(6.0)
    self.carMarker.position = self.Last_Location
    self.carMarker.position = self.Current_Location
    self.carMarker.rotation = bearing
    CATransaction.commit()
    self.driver_Last_Location = self.Current_Location
}
mugx
  • 9,869
  • 3
  • 43
  • 55
Prakash
  • 605
  • 6
  • 16

0 Answers0