我正在使用WKWebView在我的应用中显示谷歌地图。 这是网址:http://ec2-54-198-148-171.compute-1.amazonaws.com/map_question.html
以下是在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)
}
}
问题是,当我尝试与地图进行交互时,如放大缩小或滚动,那么应用程序中的地图会变为白色。 地图在网络浏览器中工作正常,但不会产生白屏。
有没有办法了解这背后的问题? 如何解决这个问题?
答案 0 :(得分:5)
问题不在WKWebView中,你试图加载的link有2k +标记,即使在PC上的Chrome浏览器上也会使MapView过载,这就是问题的根源。
可能的解决方案之一是将Marker Clustering添加到您的html / javascript代码中。您可以按official google maps documentation添加它。
官方谷歌地图标记群集库存储库为here。