Reputation: 860
here is my code
private static LatLng STREETVIEW = new LatLng(51.503635, -0.119781);
StreetViewPanorama streetViewPanorama;
StreetViewPanoramaView mStreetViewPanoramaView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_street_view);
mStreetViewPanoramaView = findViewById(R.id.streetviewpanorama);
mStreetViewPanoramaView.getStreetViewPanoramaAsync(this);
mStreetViewPanoramaView.onSaveInstanceState(savedInstanceState);
mStreetViewPanoramaView.onCreate(savedInstanceState);
}
@Override
public void onStreetViewPanoramaReady(StreetViewPanorama panorama) {
this.streetViewPanorama = panorama;
panorama.setPosition(STREETVIEW, 20, StreetViewSource.OUTDOOR);
streetViewPanorama.setOnStreetViewPanoramaChangeListener(this);
}
@Override
public void onStreetViewPanoramaChange(StreetViewPanoramaLocation streetViewPanoramaLocation) {
if (streetViewPanoramaLocation != null && streetViewPanoramaLocation.links != null) {
Toast.makeText(StreetViewActivity.this, "StreetView available here.", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(StreetViewActivity.this, "Street View not available on this location", Toast.LENGTH_SHORT).show();
//here, how to get nearest streetView within 100 meter distance .?
}
}
if streetview not available on current latlong. i want nearest streetView if available in nearest within 100 or any specified meter.
how may i achieve this in android app?
Upvotes: 2
Views: 262
Reputation: 439
Streetview are retrieved using latlng and radius. You are calling this method:
panorama.setPosition(STREETVIEW, 20, StreetViewSource.OUTDOOR);
which gets streetviews within 20 meters.
Here is signature of the method: public void setPosition (LatLng position, int radius, StreetViewSource source)
You need to pass 100 or any other number you want as radius and it'll find streetview within that radius around the given latlng.
For example, if you wanna get streetviews within 100m radius, call this:
panorama.setPosition(STREETVIEW, 100, StreetViewSource.OUTDOOR);
Upvotes: 2