I have this code to open Google Maps App with specific location and it's working but what I need is to drop a pin on that location, is it possible ?
if (UIApplication.shared.canOpenURL(URL(string:"comgooglemaps://")!)) {
UIApplication.shared.openURL(URL(string:
"comgooglemaps://?center=\(self.location.coordinate.latitude),\(self.location.coordinate.longitude)&zoom=14&views=traffic")!)
} else {
print("Can't use comgooglemaps://");
}
How to to do this ?
You should add this line in info.Plist file
code here:
First open
Info.plist
as Source Code (Righ Click on file Info.plis, then select Source Code) and add this:Next to make it easier to open Google Maps, create function like this one:
Whenever you want to open Google Maps with given coordinate, you just call the function
openGoogleMaps()
.For more check Maps URLs and Maps SDK for iOS
This is much simpler to do in 2019: just use the universal link
See the complete documentation at https://developers.google.com/maps/documentation/urls/guide .
You can use this:
Here is the Swift 5 solution, where you can be sure that the map is shown in the browser if Google Maps app is not installed or in Google Maps app if is installed on the device, both cases with the pin of the location.
Use this code for opening in google map if it's installed else open in default apple map.