alshapton alshapton - 1 year ago 87
Java Question

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".

Answer Source

I created a little hack for this. :)


<string name="html_streetview">    <![CDATA[
   <script src=";sensor=false" type="text/javascript"></script>
<script type="text/javascript">
 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) {
   } else {

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.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();

      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() {

   public void hasNotStreetview() {

   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. :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download