-1

I want to get direction from google maps in swift. In my application, user can make two markers with LongTouch and i want to show direction between markers and also i get latitude and longitude of each marker. I am amateur and couldn't find code for this.

func mapView(mapView: GMSMapView, didLongPressAtCoordinate coordinate: CLLocationCoordinate2D) {
    if counterMarker < 2
    {
        counterMarker += 1
        let marker = GMSMarker(position: coordinate)
        marker.appearAnimation = kGMSMarkerAnimationPop

        marker.map = mapView
        marker.position.latitude = coordinate.latitude
        marker.position.longitude = coordinate.longitude
        latitudeMarker = marker.position.latitude
        longitudeMarker = marker.position.longitude

        print(latitudeMarker)
        print(longitudeMarker)
        print("ok")

}
    }

how can I use google maps to get direction and time?

P.Tb
  • 99
  • 1
  • 5
  • 15

1 Answers1

-1

You can try to use Google Maps Directions API, it is a service that calculates directions between locations using an HTTP request.

You can set your two markers as the origin and destination parameters, it is the address, textual latitude/longitude value, or place ID from which you wish to calculate directions.

  • If you pass an address, the Directions service geocodes the string and converts it to a latitude/longitude coordinate to calculate directions.

origin=24+Sussex+Drive+Ottawa+ON

  • If you pass coordinates, they are used unchanged to calculate directions. Ensure that no space exists between the latitude and longitude values.

origin=41.43206,-81.38992

For more information about Directions API, just read the link above for the documentation.

You can also try to check this related SO questions.

Community
  • 1
  • 1
KENdi
  • 7,576
  • 2
  • 16
  • 31