Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ascertain Google Streetview function existence

Is there a way of ascertaining if a Google Streetview panorama is available from an Android application (i.e. using Java).

No alternatives seem to exist for PHP or Python or other server-side technologies.

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

like image 625
alshapton Avatar asked Nov 22 '10 15:11

alshapton


People also ask

How do I know if Street View is available?

Use the yellow Pegman to explore the scene. Now that you think you've found the right spot, click the Pegman to reveal the blue lines which will indicate where Street View is available. Then, click on the place you want to view and the Pegman will “drop” you into Street View.

When did Google StreetView begin?

Google Street View launched officially in 2007 and was only available for San Francisco, New York, Las Vegas, Miami and Denver.

How was Google Street View created?

Google collects Street View imagery by driving, pedaling, sailing and walking around and capturing imagery with special cameras that simultaneously collect images in multiple directions. The images are later overlapped and stitched together into a single 360-degree image.

What is Google Street View used for?

Google Street View is a feature of Google Maps that enables users to view and navigate through 360 degree horizontal and 290 degree vertical panoramic street level images of various cities around the world.


1 Answers

I created a little hack for this. :)

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>

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

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

like image 108
alosdev Avatar answered Oct 05 '22 08:10

alosdev