0

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.

Ali asghar
  • 29
  • 2

1 Answers1

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