谷歌街景的存在功能 - JavaScript不 [英] Google Streetview existence function - NOT Javascript

查看:178
本文介绍了谷歌街景的存在功能 - JavaScript不的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有查明的方式,如果一个谷歌街景全景可从一个Android应用程序(即使用Java)。我所看到的其他问题,说明有一个Javascript功能可用,但没有其他选择似乎存在PHP或者Python或其他服务器端technologuies。

Is there a way of ascertaining if a Google Streetview panorama is available from an Android application (i.e. using Java). I have seen other questions stating that there is a Javascript function available, but no alternatives seem to exist for PHp or Python or other server-side technologuies.

调用谷歌街景在没有全景存在的影响仅仅是一个黑色的屏幕和一个spinny的事情。

The impact of calling Google Streetview where no panorama exists is simply a black screen and a "spinny thing".

有没有吨左右任何方式 他的? 感谢您的时间......

Is there any way around t his? Thanks for your time.....

推荐答案

我创建了一个小黑客此。 :)

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&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>

现在的活动街景添加一个按钮,并把这个下面code到的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);

和现在的活动的内部类:

And now the inner Class of the 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
   }
}

这AA很坏的解决办法,但可能会有所帮助。 :)

this a a rather bad workaround but probably can help. :)

这篇关于谷歌街景的存在功能 - JavaScript不的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆