It's not a bug but something unwanted code is there or has some brackets issue.
For better code make a separate function for navigating to Google Maps.
struct ContentView: View {
var body: some View {
Button ("Open Google Map") {
let toLatitude = (self.destinationLocation?.latitude)!
let toLongitude = (self.destinationLocation?.longitude)!
let fromLatitude = 10.00
let fromLongitude = 10.00
self.navigateOnGoogleMap(sourceLatitude: fromLatitude, sourceLongitude: fromLongitude, destinationLatitude: toLatitude, destinationLongitude: toLongitude)
}
}
func navigateOnGoogleMap(sourceLatitude : Double, sourceLongitude : Double, destinationLatitude : Double, destinationLongitude : Double) {
let urlGoogleMap : URL = URL(string: "comgooglemaps://?saddr=\(sourceLatitude),\(sourceLongitude)&daddr=\(destinationLatitude),\(destinationLongitude)&directionsmode=driving")!
if UIApplication.shared.canOpenURL(urlGoogleMap) {
UIApplication.shared.open(urlGoogleMap, options: [:], completionHandler: nil)
} else {
let urlString = URL(string:"http://maps.google.com/?saddr=\(sourceLatitude),\(sourceLongitude)&daddr=\(destinationLatitude),\(destinationLongitude)&directionsmode=driving")
UIApplication.shared.open(urlString!, options: [:], completionHandler: nil)
}
}
}