Reputation: 85
When I click the button my app shows a map: it opens the google map perfectly in the browser safari.
Now I just want to show the map into a UIWebView
.
Here is the code I use to show the map:
@IBAction func newAction(sender: UIBarButtonItem) {
if (UIApplication.sharedApplication().canOpenURL(NSURL(string:"comgooglemaps://")!)) {
UIApplication.sharedApplication().openURL(NSURL(string:
"http://maps.google.com/maps?daddr=" + self.longitud + "," + self.latitud + "&saddr=" + self.lat1 + "," + self.long1 + "&views=traffic")!)
} else {
mostrarAlerta("Por favor descarga e instala google map desde el AppleStore")
}
}
Upvotes: 3
Views: 4281
Reputation: 42449
Just display UIWebView on the IBAction? You're going to want something like this:
@IBAction func newAction(sender: UIBarButtonItem) {
// set up webview
let webView = UIWebView(frame: self.view.frame) // or pass in a CGRect frame of your choice
// add webView to current view
self.view.addSubview(webView)
self.view.bringSubviewToFront(webView)
// load the Google Maps URL
webView.loadRequest(NSURLRequest(URL: NSURL(string: "http://maps.google.com/maps?daddr=" + self.longitud + "," + self.latitud + "&saddr=" + self.lat1 + "," + self.long1 + "&views=traffic")!))
}
Upvotes: 3