als*_*ton 14 java android google-street-view
有没有办法确定Android应用程序(即使用Java)是否提供Google Streetview全景图.
似乎没有替代PHP或Python或其他服务器端技术的替代品.
调用谷歌街景没有全景的影响只是一个黑屏和一个"旋转的东西".
我为此创建了一个小黑客.:)
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>
Run Code Online (Sandbox Code Playgroud)
现在在活动上添加街景视图按钮,并将以下代码放入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);
Run Code Online (Sandbox Code Playgroud)
而现在活动的内部类:
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
}
}
Run Code Online (Sandbox Code Playgroud)
这是一个相当糟糕的解决方法,但可能会有所帮助.:)
| 归档时间: |
|
| 查看次数: |
3442 次 |
| 最近记录: |