79216993

Date: 2024-11-23 02:05:21
Score: 3
Natty:
Report link

I want to leave this solution here for anyone trying to add the pin and show the actual place card with name and details (instead of just a pin with coordinates):

if (UIApplication.shared.canOpenURL(URL(string:"comgooglemaps://")!)) {
    let encodedName = self.location.name.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? ""
    let googleMapsURL = "comgooglemaps://?q=\(encodedName)&center=\(self.location.coordinate.latitude),\(self.location.coordinate.longitude)&views=satellite&zoom=15"
    UIApplication.shared.open(URL(string: googleMapsURL)!, options: [:], completionHandler: nil)
} else {
    print("Can't use comgooglemaps://")
}

This works perfectly if there's only one place with that specific name. Unfortunately, if there are multiple places with the same name (like if there's a bus station right next to your location), it will show a list of all matching places. I haven't found a way to only get the wanted place, even if I use it's ID.

Note: This solution requires the place name (location.name) in addition to the coordinates.

If anyone has a better solution that can handle multiple places with the same name, please share it in the comments as I'm also looking for one!

Reasons:
  • RegEx Blacklisted phrase (2.5): please share
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: fran.stante