如何将 Google 地图显示到 WebView 中?

How can I show Google Maps into a WebView?

当我单击按钮时,我的应用程序会显示一张地图:它会在浏览器 safari 中完美打开 google 地图。

现在只想把地图显示成UIWebView

这是我用来显示地图的代码:

@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")
    }
}

只在IBAction上显示UIWebView?你会想要这样的东西:

@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")!))
}