I have a classified application. When posting an ad you need to give your location as a viewer i can see the marked location and map-view but the marked location only open in the google maps when i tap the google button on the bottom left corner of gmsmapview. I want the user to be enable to open the marked location in google maps when he taps anywhere in the map. Is there any function that detects tap anywhere on the map.
Asked
Active
Viewed 274 times
0
-
Check https://stackoverflow.com/a/54767602/5519329 – Sateesh Yemireddi Apr 22 '20 at 06:31
-
I figured it out thanks for the help. But stuck with an error : -canOpenURL: failed for URL: "comgooglemaps://" - error: "The operation couldn’t be completed. (OSStatus error -10814.)" – Ali asghar Apr 24 '20 at 11:38
-
Do you have Google Maps installed in your device? – Sateesh Yemireddi Apr 24 '20 at 11:45
-
no but if it's not installed then it should open the URL – Ali asghar Apr 24 '20 at 20:45
1 Answers
0
This code will check if google maps are installed. If yes it will open location in maps else will open the location in safari.
func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {
if(self.current_long != "" && self.current_lat != "")
{
//Add your latitude
let lat: String = self.current_lat
//Add your longitude
let lon: String = self.current_long
if (UIApplication.shared.canOpenURL(URL(string:"comgooglemaps://")!)) {
UIApplication.shared.open(URL(string:"comgooglemaps://?center=\(lat),\(lon)&zoom=14&views=traffic&q=\(lat),\(lon)")!, options: [:], completionHandler: nil)
}else{
print("Cannot open maps")
if let urlDestination = URL.init(string: "https://www.google.com/maps/?center=\(lat),\(lon)&zoom=14&views=traffic&q=\(lat),\(lon)"){
UIApplication.shared.open(urlDestination, options: [:], completionHandler: nil)
}
}
}
}

Ali asghar
- 29
- 2