2017-01-16 107 views
5

我正在使用WKWebView在我的應用程序中顯示谷歌地圖。 這是網址:http://ec2-54-198-148-171.compute-1.amazonaws.com/map_question.htmlWebView變白/空白

以下是在App,以顯示該WKWebView代碼:

import UIKit 
import WebKit 
import Foundation 
class MyMapController: UIViewController, UIScrollViewDelegate, WKScriptMessageHandler { 
var webViewGeo: WKWebView? 
var WidgetView:UIView = UIView() 

    override func loadView() { 
    super.loadView() 

    let contentController = WKUserContentController();  
    contentController.addScriptMessageHandler(
     self, 
     name: "callbackHandler" 
    ) 


    let config = WKWebViewConfiguration() 
    config.userContentController = contentController 


    self.webViewGeo = WKWebView(
     frame: self.WidgetView.bounds, 
     configuration: config 
    ) 
    self.WidgetView = self.webViewGeo!  
} 



override func viewDidLoad() { 
     super.viewDidLoad()  
     let frame = CGRect(x:0, y:-20, width:self.view.bounds.width, height:self.view.bounds.width) 
     WidgetView.frame=frame  
     let url = NSURL(string:"http://ec2-54-198-148-171.compute-1.amazonaws.com/map_question.html") 
     let req = NSURLRequest(URL:url!) 
     self.webViewGeo!.loadRequest(req) 
     self.view.addSubview(WidgetView)    
    } 

} 

問題是,當我嘗試像地圖交互放大縮小或放大,然後滾動我的地圖在應用程序變成白色。 地圖在Web瀏覽器中正常工作,不會導致白屏。

有沒有辦法瞭解背後的問題? 如何解決這個問題?

+0

該映射甚至會減慢我的臺式電腦;我不知道iOS是否能夠實時處理這些問題。 – holex

+4

「我正在使用WKWebView在我的應用中顯示谷歌地圖」但Google爲您提供了一個API。爲什麼不使用它呢? – matt

+0

我不得不使用融合層和數據層。這些在iOS版本的Google地圖中不可用。 – dang

回答

5

的問題是不是在WKWebView的link你試圖裝入具有2K +標記,超載的MapView即使是在PC上的Chrome瀏覽器,這是你的問題的根源。

可能的解決方案之一是將Marker Clustering添加到您的html/javascript代碼。您可以按照official google maps documentation添加它。

官方谷歌地圖標記clusterer庫存儲庫是here