Dolleno Dolleno - 1 year ago 133
Swift Question

Swift iOS google Map, path to coordinate

I am trying to create a function in my app that will guide the user to a marker I have created.
This is the code I am using, it works great, It gets the users current location and show it on the map. But how can I get a directions to a marker?

Any awnser will be helpful

class Karta: UIViewController, CLLocationManagerDelegate {
@IBOutlet var mapView: GMSMapView!

let locationManager = CLLocationManager()

override func viewDidLoad() {

//allow app to track user
locationManager.delegate = self

//set out a marker on the map
var marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(56.675907, 12.858798)
marker.appearAnimation = kGMSMarkerAnimationPop
marker.icon = UIImage(named: "flag_icon") = mapView

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "Types Segue" {
let navigationController = segue.destinationViewController as UINavigationController

func locationManager(manager: CLLocationManager!, didChangeAuthorizationStatus status: CLAuthorizationStatus) {

//If map is being used
if status == .AuthorizedWhenInUse {
var myLocation = mapView
mapView.myLocationEnabled = true
mapView.settings.myLocationButton = true

func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
if let location = locations.first as? CLLocation { = GMSCameraPosition(target: location.coordinate, zoom: 15, bearing: 0, viewingAngle: 0)

Answer Source

Unlike Apple's MapKit, the Google Maps SDK for iOS does not natively include a way to perform route calculations.

Instead, you need to use the Google Directions API: It is an HTTP-only API, and Google does not provide any SDK as of today, but you can easily write your own wrapper yourself, or choose one of the many options available on Github:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download