Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Street view + device tilting

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");
            }
        });
    }
}
like image 367
Greg Avatar asked Apr 06 '17 14:04

Greg


1 Answers

I'm not sure given your question, so comment if i'm wrong but it seems you're able to rotate through this instruction

panorama.animateTo(camera, duration);

and you're moving to a specific location using the "camera" variable you built before.

So, if i understand correctly what you are trying to do, you have to check for mobilephone sensors (accelerometer & position) to get the motion then apply the correct motion to the panorama. Take a look at android sensor documentation in order to get the proper listeners (or how to register a sensor usage) then build the correct camera object according to the acceleration registered by the phone (left acceleration -> rotating left, right acceleration --> rotating right).

If you need a code example i'd suggest you to look this question which has some other links to help you using sensors and getting more doc.

If this does not help, comment and/or clarify the question.

like image 59
Feuby Avatar answered Nov 13 '22 04:11

Feuby