确定Google Streetview功能存在 [英] Ascertain Google Streetview function existence
问题描述
是否有办法确定Android应用程序(即使用Java)是否提供Google Streetview全景图。
Is there a way of ascertaining if a Google Streetview panorama is available from an Android application (i.e. using Java).
对于PHP或Python或其他服务器端技术,似乎没有替代方案。
No alternatives seem to exist for PHP or Python or other server-side technologies.
呼叫的影响没有全景的Google街景只是一个黑屏和一个旋转的东西。
The impact of calling Google Streetview where no panorama exists is simply a black screen and a "spinning thing".
推荐答案
我为此创建了一个小黑客。 :)
I created a little hack for this. :)
strings.xml
strings.xml
<string name="html_streetview"> <![CDATA[
<html>
<head>
<script src="http://maps.google.com/maps/api/js?v=3&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>
现在在活动上添加街景视图按钮,并将以下代码放入onclick方法:
now add a button for streetview on the activity and put this following code into the onclick method:
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);
现在活动的内部类别:
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
}
}
这是一个相当糟糕的解决方法,但可能会有所帮助。 :)
this a a rather bad workaround but probably can help. :)
这篇关于确定Google Streetview功能存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!