0

I'm currently making a geoguessr replica using the street view API and maps SDK reliant on randomly generated coordinates. As one could guess, more often than not my coordinates are a location without a streetview image. My code is as follows:

 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        SupportStreetViewPanoramaFragment streetViewPanoramaFragment = (SupportStreetViewPanoramaFragment)getSupportFragmentManager().findFragmentById(R.id.googlemapstreetview);
        streetViewPanoramaFragment.getStreetViewPanoramaAsync(this);

        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map_fragment);
        mapFragment.getMapAsync(this);

    }



    @Override
    public void onStreetViewPanoramaReady(StreetViewPanorama streetViewPanorama) {

        Random random = new Random();
        double lat = MIN_LATITUDE + (MAX_LATITUDE - MIN_LATITUDE) * random.nextDouble();
        double lng = MIN_LONGITUDE + (MAX_LONGITUDE - MIN_LONGITUDE) * random.nextDouble();
        randomLocation = new LatLng(lat,lng);

        this.streetViewPanorama = streetViewPanorama;
        this.streetViewPanorama.setPosition(randomLocation);
    }

    @Override
    public void onMapReady(@NonNull GoogleMap googleMap) {
        this.googleMap = googleMap;

        MarkerOptions markerOptions = new MarkerOptions().position(randomLocation);
        Marker marker = googleMap.addMarker(markerOptions);
        googleMap.moveCamera(CameraUpdateFactory.newLatLng(randomLocation));
    }
}

How should I go about making it so that my program keeps trying until it pulls coordinates with a street view location? Either that or maybe even rather just use the original coordinates and try to find the closest available streetview to those coordinates?

bofa
  • 19
  • 2
  • `set_position` has a radius parameter so you could use the listener `onStreetViewPanoramaChange` (which you would set in the `onStreetViewPanoramaReady` method) to determine if it is valid and if not set position with larger radius..etc. See: https://stackoverflow.com/questions/51571394/if-streetview-is-not-available-for-a-specified-latlong-how-to-get-the-nearest-a. – Computable Apr 19 '23 at 16:48

0 Answers0