簡體   English   中英

如何將Google地圖顯示為WebView?

[英]How can I show Google Maps into a WebView?

當我點擊按鈕時,我的應用程序會顯示一張地圖:它會在瀏覽器的Safari中完美地打開谷歌地圖。

現在我只想將地圖顯示到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")!))
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM