Reputation: 338
I'm new to swift programming and I stumbled upon a problem which can't seem to find a solution after searching the web.
What i'm trying to do is when a button is tapped in my application I want the Google maps app to launch but after implementing the code I get the error: Cannot call value of non-function type UIApplication
Am I missing something?
import UIKit
import GoogleMaps
class MapDisplayViewController: UIViewController, GMSMapViewDelegate, CLLocationManagerDelegate, UIApplicationDelegate {
@IBOutlet weak var openDirections: UIButton!
@IBAction func openMapsDirection(_ sender: UIButton!) {
if (UIApplication.sharedApplication().canOpenURL(NSURL(string:"comgooglemaps://")!)) {
UIApplication.sharedApplication().openURL(NSURL(string:
"comgooglemaps://?center=40.765819,-73.975866&zoom=14&views=traffic")!)
} else {
print("Can't use comgooglemaps://");
}
}
}
Upvotes: 1
Views: 5414
Reputation: 7591
In Swift 3 sharedApplication()
has been replaced with a property called shared
.
Try updating your code:
if (UIApplication.shared.canOpenURL(NSURL(string:"comgooglemaps://")!)) {
UIApplication.shared.openURL(NSURL(string:
"comgooglemaps://?center=40.765819,-73.975866&zoom=14&views=traffic")!)
} else {
print("Can't use comgooglemaps://");
}
Upvotes: 7
Reputation: 434
"comgooglemaps:// and comgooglemaps-x-callback:// - These schemes allow you to launch the Google Maps app for iOS and perform one of several actions"
Please make sure that your device already installed Google Maps app. https://developers.google.com/maps/documentation/ios-sdk/urlscheme
Hope this will help you.
Upvotes: -1