Just call this method and add Google Maps URL Scheme into your .plist file same as this Answer.
Swift-4 :-
func openMapApp(latitude:String, longitude:String, address:String) {
var myAddress:String = address
//For Apple Maps
let testURL2 = URL.init(string: "http://maps.apple.com/")
//For Google Maps
let testURL = URL.init(string: "comgooglemaps-x-callback://")
//For Google Maps
if UIApplication.shared.canOpenURL(testURL!) {
var direction:String = ""
myAddress = myAddress.replacingOccurrences(of: " ", with: "+")
direction = String(format: "comgooglemaps-x-callback://?daddr=%@,%@&x-success=sourceapp://?resume=true&x-source=AirApp", latitude, longitude)
let directionsURL = URL.init(string: direction)
if #available(iOS 10, *) {
UIApplication.shared.open(directionsURL!)
} else {
UIApplication.shared.openURL(directionsURL!)
}
}
//For Apple Maps
else if UIApplication.shared.canOpenURL(testURL2!) {
var direction:String = ""
myAddress = myAddress.replacingOccurrences(of: " ", with: "+")
var CurrentLocationLatitude:String = ""
var CurrentLocationLongitude:String = ""
if let latitude = USERDEFAULT.value(forKey: "CurrentLocationLatitude") as? Double {
CurrentLocationLatitude = "\(latitude)"
//print(myLatitude)
}
if let longitude = USERDEFAULT.value(forKey: "CurrentLocationLongitude") as? Double {
CurrentLocationLongitude = "\(longitude)"
//print(myLongitude)
}
direction = String(format: "http://maps.apple.com/?saddr=%@,%@&daddr=%@,%@", CurrentLocationLatitude, CurrentLocationLongitude, latitude, longitude)
let directionsURL = URL.init(string: direction)
if #available(iOS 10, *) {
UIApplication.shared.open(directionsURL!)
} else {
UIApplication.shared.openURL(directionsURL!)
}
}
//For SAFARI Browser
else {
var direction:String = ""
direction = String(format: "http://maps.google.com/maps?q=%@,%@", latitude, longitude)
direction = direction.replacingOccurrences(of: " ", with: "+")
let directionsURL = URL.init(string: direction)
if #available(iOS 10, *) {
UIApplication.shared.open(directionsURL!)
} else {
UIApplication.shared.openURL(directionsURL!)
}
}
}
Hope, this is what you're looking for. Any concern get back to me. :)