I'm trying to add an activity as a feature to an app I'm building where, the API will return a lat long, and with this lat long I will load google street view. Which with the movement of the device, will rotate the 360 degree angle of the position. I'm struggling on the movement part of the device. Using your fingers on the screen you can rotate. I wonder if anyone can point me in the right direction in getting the device movement to affect the position of the street view?
The code I have so far is:
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import com.google.android.gms.maps.OnStreetViewPanoramaReadyCallback;
import com.google.android.gms.maps.StreetViewPanorama;
import com.google.android.gms.maps.StreetViewPanoramaFragment;
import com.google.android.gms.maps.StreetViewPanoramaOptions;
import com.google.android.gms.maps.StreetViewPanoramaView;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.StreetViewPanoramaCamera;
import com.google.android.gms.maps.model.StreetViewPanoramaLocation;
public class MainActivity extends FragmentActivity
implements OnStreetViewPanoramaReadyCallback {
private static final String TAG = MainActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StreetViewPanoramaFragment streetViewPanoramaFragment =
(StreetViewPanoramaFragment) getFragmentManager()
.findFragmentById(R.id.streetviewpanorama);
streetViewPanoramaFragment.getStreetViewPanoramaAsync(this);
}
@Override
public void onStreetViewPanoramaReady(final StreetViewPanorama panorama) {
final long duration = 1000;
float tilt = 30;
float bearing = 90;
final StreetViewPanoramaCamera camera = new StreetViewPanoramaCamera.Builder()
.zoom(panorama.getPanoramaCamera().zoom)
.bearing(bearing)
.tilt(tilt)
.build();
panorama.setPosition(new LatLng(52.208818, 0.090587));
panorama.setStreetNamesEnabled(false);
panorama.setZoomGesturesEnabled(false);
panorama.setOnStreetViewPanoramaChangeListener(new StreetViewPanorama.OnStreetViewPanoramaChangeListener() {
@Override
public void onStreetViewPanoramaChange(StreetViewPanoramaLocation streetViewPanoramaLocation) {
if (streetViewPanoramaLocation != null) {
panorama.animateTo(camera, duration);
}
Log.d(TAG, "TESTINGGGGGGGGGG");
}
});
}
}