Arwen Ghafur
Arwen Ghafur

Reputation: 5

Get Directions using Google Maps API in iOS

I am a Swift/iOS beginner and I want to use Google Maps API to draw direction between to locations, I now how to do this using MapKit but MapKit dose not support directions in Iraq.

Can someone help me get started with Google Maps? I need this for my project.

Upvotes: 0

Views: 561

Answers (1)

Sachin Amrale
Sachin Amrale

Reputation: 297

You can use Directly Google map to get the direction from your current location to desire location by using following lines of code

(If you have "Google Map" App in your phone if loop will execute otherwise else loop will execute and open google map on your web browser)

if (UIApplication.shared.canOpenURL(URL(string:"comgooglemaps://")!)) {
                UIApplication.shared.openURL(NSURL(string:
                    "comgooglemaps://?saddr=&daddr=\(Float((Yourcoordinate.latitude)!)),\(Float((Yourcoordinate.longitude)!))&directionsmode=driving")! as URL)

            } else {

                let url = "https://www.google.co.in/maps/dir/?saddr=&daddr=\(Float((Yourcoordinate.latitude)!)),\(Float((Yourcoordinate.longitude)!))"
                UIApplication.shared.openURL(NSURL(string:url)! as URL)
            }

Hope this will help...

Upvotes: 3

Related Questions