gpt4 book ai didi

java - 确定谷歌街景功能存在

转载 作者:搜寻专家 更新时间:2023-10-30 19:45:22 24 4
gpt4 key购买 nike

有没有一种方法可以确定 Android 应用程序(即使用 Java)是否提供 Google 街景全景图。

PHP、Python 或其他服务器端技术似乎不存在替代方案。

在不存在全景图的情况下调用 Google 街景的影响只是黑屏和“旋转的东西”。

最佳答案

我为此创建了一个小技巧。 :)

字符串.xml

<string name="html_streetview">    <![CDATA[
<html>
<head>
<script src="http://maps.google.com/maps/api/js?v=3&amp;sensor=false" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
Android.echo();
var testPoint = new google.maps.LatLng(%1$s, %2$s,true);
var svClient = new google.maps.StreetViewService();
svClient.getPanoramaByLocation(testPoint, 50,function (panoramaData, status) {
if (status == google.maps.StreetViewStatus.OK) {
Android.hasStreetview();
} else {
Android.hasNotStreetview();
}
});
</script>
</body>
</html>
]]>
</string>

现在在 Activity 上添加一个街景按钮,并将以下代码放入 onclick 方法中:

    if (webView == null) {
webView = new WebView(this);
webView.setVisibility(View.INVISIBLE);
webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(new JavascriptCheck(this), "Android");
webView.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(this, "Streetview loading", Toast.LENGTH_SHORT).show();
super.onReceivedError(view, errorCode, description, failingUrl);
}
});
}

Toast.makeText(this, "Streetview loading", Toast.LENGTH_SHORT).show();

webView.loadDataWithBaseURL(baseurl,
getString(R.string.html_streetview, latitude, longitude), "text/html", "UTF-8", baseurl);

现在是 Activity 的内部类:

public class JavascriptCheck {
private final Context context;

public JavascriptCheck(Context context) {
this.context = context;
}

public void echo() {
Log.d("JavascriptChecker", "javascript called");
}

public void hasStreetview() {
pushStreetviewState(true);
}

public void hasNotStreetview() {
pushStreetviewState(false);
}

private void pushStreetviewState(final boolean hasStreetview) {
Log.d("JavascriptChecker", hasStreetview);
// TODO do your stuff needed here
}
}

这是一个相当糟糕的解决方法,但可能会有所帮助。 :)

关于java - 确定谷歌街景功能存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4247044/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com