How to show Google Maps in WebView?
When I click the button, my app shows the map: it opens google map fine in safari browser.
Now I just want to show the map in UIWebView
.
Here is the code I'm using to display 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")
}
}
+3
source to share
1 answer
Just display UIWebView on IBAction? You need 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")!))
}
+3
source to share