Rahul Rahul - 2 months ago 7
Android Question

How to pass latitude and longitude to Pasnormastreetview to show the street view

This is the view. here i have added the StreetViewPanormaFragment



<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/street_view_panorama_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.soulsystem_4.myapplication.MapsActivity"
class="com.google.android.gms.maps.StreetViewPanoramaFragment"/>





This is the class in which i want to pass the latitude and longitude for that view. How to pass.



private static final String EXTRA_LONG = "current_long";
private static final String EXTRA_LAT = "current_lat";
private static final String EXTRA_BEARING = "current_bearing";
private static final String EXTRA_TILT = "current_tilt";
private static final String EXTRA_ZOOM = "current_zoom";

private GoogleApiClient mLocationClient;
private Location mCurrentLocation;
private float mBearing;
private float mTilt;
private float mZoom;

private StreetViewPanorama mPanorama;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.street_view_panorama_fragment);
mapFragment.getMapAsync(this);
}
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;

// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}

@Override
public void onConnected(@Nullable Bundle bundle) {

}

@Override
public void onConnectionSuspended(int i) {

}

@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {

}
}





I just want street view for location which i will pass to that view.

Answer

private static final LatLng SYDNEY = new LatLng(-33.87365, 151.20689);

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);

    StreetViewPanoramaFragment streetViewPanoramaFragment =
            (StreetViewPanoramaFragment) getFragmentManager()
                    .findFragmentById(R.id.street_view_panorama_fragment);
    streetViewPanoramaFragment.getStreetViewPanoramaAsync(this);

}