3

I have added a route and i have also added the way point markers. i want to move the marker smoothly from one gps coordinate point to another smoothly along the route. can anyone help me with this? here is the code that is used to add markers.

func configureMapAndMarkersForRoute() {
  viewGMap.camera = GMSCameraPosition.cameraWithTarget(mapTasks.originCoordinate, zoom: 9.0)

  originMarker = GMSMarker(position: self.mapTasks.originCoordinate)
  originMarker.map = self.viewGMap
  originMarker.icon = GMSMarker.markerImageWithColor(UIColor.greenColor())
  originMarker.title = self.mapTasks.originAddress

  destinationMarker = GMSMarker(position: self.mapTasks.destinationCoordinate)
  destinationMarker.map = self.viewGMap
  destinationMarker.icon = GMSMarker.markerImageWithColor(UIColor.redColor())
  destinationMarker.title = self.mapTasks.destinationAddress

  if waypointsArray.count > 0 {
    var i = 0
    for waypoint in waypointsArray {
      let lat: Double = (waypoint.componentsSeparatedByString(",")[0] as NSString).doubleValue
      let lng: Double = (waypoint.componentsSeparatedByString(",")[1] as NSString).doubleValue

      let marker = GMSMarker(position: CLLocationCoordinate2DMake(lat, lng))
      marker.map = viewGMap
      marker.icon = GMSMarker.markerImageWithColor(UIColor.purpleColor())
      marker.title = locationNameArray[i]
      markersArray.append(marker)
      i += 1
    }
  }
}
Sahil Kapoor
  • 11,183
  • 13
  • 64
  • 87
Ganesh Kumar
  • 1,631
  • 2
  • 21
  • 35

3 Answers3

6

Swift:

func updateMarker(coordinates: CLLocationCoordinate2D, degrees: CLLocationDegrees, duration: Double) {
    // Keep Rotation Short
    CATransaction.begin()
    CATransaction.setAnimationDuration(0.5)
    marker.rotation = degrees
    CATransaction.commit()

    // Movement
    CATransaction.begin()
    CATransaction.setAnimationDuration(duration)
    marker.position = coordinates

    // Center Map View
    let camera = GMSCameraUpdate.setTarget(coordinates)
    mapView.animateWithCameraUpdate(camera)

    CATransaction.commit()
}
Sahil Kapoor
  • 11,183
  • 13
  • 64
  • 87
4

Check below code ...

[CATransaction begin];
[CATransaction setAnimationDuration:5.0];
CGPoint point = [mapView.projection pointForCoordinate:destCoordinate];
//    point.x = point.x + 100;
GMSCameraUpdate *camera =
[GMSCameraUpdate setTarget:[mapView.projection coordinateForPoint:point]];
[mapView animateWithCameraUpdate:camera];
markerToMove.position = destCoordinate;
[CATransaction commit];

loop through all points you getting for path ..and set next destCoordinate as each next point ....

dev_m
  • 796
  • 6
  • 12
0
var driverPositionMarker: GMSMarker?

func displayDriverPosition(on mapView: GMSMapView, with coordinate: CLLocationCoordinate2D) {
        if let marker = driverPositionMarker {
            let heading = GMSGeometryHeading(marker.position, coordinate)
            marker.rotation = heading
            marker.position = coordinate
        } else {
            let marker = GMSMarker()
            marker.position = coordinate
            marker.iconView = UIImageView(image: #imageLiteral(resourceName: "CarMarker"))
            marker.map = mapView
            driverPositionMarker = marker
        }
}
user3672430
  • 106
  • 1
  • 5