iOS下如何加载Google StreetViewCoverageLayer?

问题描述

我的 iOS 应用使用街景全景图。
为了让用户选择街景覆盖的路线,我想用街景覆盖覆盖 Google 地图。
这样的层由 StreetViewCoverageLayersee here 在 Google JavaScript SDK 中提供。
不幸的是,这个类在 iOS SDK 中似乎不可用。
作为一种解决方法,我尝试在我的 iOS 应用程序中集成 Javascript 代码,遵循 this excellent tutorial
因此,我的 JavaScript 代码调用,但引发异常(如预期)。

这是我的 iOS 代码

func initializeJS() {
    jscontext = jscontext()    

    // Add an exception handler.
    self.jscontext.exceptionHandler = { context,exception in
        if let exc = exception {
            print("JS Exception:",exc.toString()!)
        }
    }
    
    // Specify the path to the jssource.js file.
    if let jsSourcePath = Bundle.main.path(forResource: "JavaScript",ofType: "js") {
        do {
            // Load its contents to a String variable.
            let jsSourceContents = try String(contentsOfFile: jsSourcePath)
            
            // Add the Javascript code that currently exists in the jsSourceContents to the Javascript Runtime through the jscontext object.
            jscontext.evaluateScript(jsSourceContents)
        }
        catch {
            print(error.localizedDescription)
        }
    }    
}

func jsDemo1() {
    if let getStreetViewCoverageLayer = self.jscontext.objectForKeyedSubscript("getStreetViewCoverageLayer") {
        if let result = getStreetViewCoverageLayer.call(withArguments: nil) {
            print(result.toString()!)
        }
    }  

这是测试 JavaScript 代码

function getStreetViewCoverageLayer() {
    var streetViewLayer = new google.maps.StreetViewCoverageLayer();
    return "getStreetViewCoverageLayer"
}  

当我运行应用程序时,它会调用 JavaScript 异常处理程序并打印

JS Exception: ReferenceError: Can't find variable: google  

这很清楚,因为 google 没有定义。当然我知道我应该先用

之类的东西联系谷歌服务器
'https://maps.googleapis.com/maps/api/js?v=3' + '&key=<MY_API_KEY>&callback=initialize'

我的问题是:
如何在我的 JavaScript 代码中执行此操作?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...