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.
Builder builder = new LatLngBounds.Builder();
double antartica[] = {-62.5670958528642, -59.92767333984375, -62.584805850293485, -59.98260498046875, -62.61450963659083};
for (int i = 0; i < 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();
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.
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.
I am aware that you can accomplish this using the JavaScript API v3 following this link.
You would do something like this:
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
}
});
But I am hoping to do this using Android only. I am using the Google Play Services API by the way, and not the Google Maps v2 Android.
Can anyone shed some light?
EDIT:
Following ratana's suggestion, this is what I have so far:
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());
}
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…