title: How to check if position if valid in StreetView in Android
body: <p>I have an app that is randomly generating positions in a GoogleMaps based on a defined boundary. So I first generate a random LatLng and then I verify if this point is inside my boundary. If it is, it's valid.</p>
  
  <pre><code>Builder builder = new LatLngBounds.Builder();
  
          double antartica[] = {-62.5670958528642, -59.92767333984375, -62.584805850293485, -59.98260498046875, -62.61450963659083};
          for (int i = 0; i &lt; antartica.length; i++) {
              builder.include(new LatLng(antartica[i],antartica[++i]));
          }
          pAntarctica = builder.build();
  
  LatLng point = generateRandomPosition();
      if(isWithinBoundaries(point))
          return point;
      else
          return getValidPoint();
  </code></pre>
  
  <p>So after this, I end up with the valid point. My problem is that a valid point in Google Maps is not necessarily valid in StreetView. </p>
  
  <p>It might happen that this random point is somewhere in the globe not yet mapped in StreetView. I need it to be valid there as well.</p>
  
  <p>I am aware that you can accomplish this using the JavaScript API v3 following this <a href="https://developers.google.com/maps/documentation/javascript/reference#StreetViewService" rel="nofollow noreferrer">link</a>.</p>
  
  <p>You would do something like this:</p>
  
  <pre><code>var latLng = new google.maps.LatLng(12.121221, 78.121212);
              streetViewService.getPanoramaByLocation(latLng, STREETVIEW_MAX_DISTANCE, function (streetViewPanoramaData, status) {
                  if (status === google.maps.StreetViewStatus.OK) {
                      //ok
                  } else {
                      //no ok
                  }
              });
  </code></pre>
  
  <p>But I am hoping to do this using Android only. I am using the Google Play Services API by the way, and <strong>not</strong> the Google Maps v2 Android.</p>
  
  <p>Can anyone shed some light?</p>
  
  <p><strong>EDIT:</strong>
  Following ratana's suggestion, this is what I have so far:</p>
  
  <pre><code>svpView.getStreetViewPanoramaAsync(new OnStreetViewPanoramaReadyCallback() {
              @Override
              public void onStreetViewPanoramaReady(final StreetViewPanorama panorama) {
                  for(final LatLng point : points) {
                      System.out.println(point.latitude + " " + point.longitude);     
                      panorama.setPosition(point, 1000);
  
                      final CountDownLatch latch = new CountDownLatch(1);
  
                      mHandlerMaps.post(new Runnable() {
                          @Override
                          public void run() {
                              if (panorama.getLocation() != null) {
                                  System.out.println("not null " + panorama.getLocation().position);
                                  writeToFile(panorama.getLocation().position.toString());
                                  l.add(point);
                              }
                              latch.countDown();
                          }
                      });
  
                      try {
                          latch.await(4, TimeUnit.SECONDS);
                      } catch (InterruptedException e) {
                          e.printStackTrace();
                      }
                  }
                  System.out.println(l.toString());
              }
          });
  </code></pre>