androidMaster
androidMaster

Reputation: 11

Android - How can I achieve this Google Maps animation?

This is how I'm currently using my google map;

        mapFragment = ((SupportMapFragment) getChildFragmentManager()
                .findFragmentById(R.id.map)).getMap();
        mapFragment.setMyLocationEnabled(true);
        mapFragment.setMapType(GoogleMap.MAP_TYPE_HYBRID);
        mapFragment.getUiSettings().setMapToolbarEnabled(false);
        mapFragment.getUiSettings().setScrollGesturesEnabled(false);
        mapFragment.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);

It produces a full screen map which for some reason is completely zoomed into the ocean so the map is just one big, blue pixel until you keep zooming out.

What I want to do:

I have looked online, tried a few things and haven't had any luck with this. If anybody can walk me through this or give me a link to a nice guide it would be highly appreciated!

Upvotes: 1

Views: 765

Answers (1)

kaho
kaho

Reputation: 4784

To achieve what you want, you should:
1) get the user's position, you can use the last known position so that your main activity would not hang and wait for the GPS return a location.

    LocationManager locationManager = (LocationManager)getSystemService
            (Context.LOCATION_SERVICE);
    Location getLastLocation = locationManager.getLastKnownLocation
            (LocationManager.PASSIVE_PROVIDER);

2) set the zoom level to 1, which is the smallest zoom level, the 2D globe; also you can center the map using the user location too.

    googleMap.moveCamera(CameraUpdateFactory.zoomTo(1));

3) animate the camera to zoom into the user location with a zoom level 20 (the largest zoom level). One thing to notice is that, you might want to wait until the 2D globe maps is loaded so that user can see the zoom happens.

        googleMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
            public void onMapLoaded() {
                googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder()
                        .target(new LatLng(userLocation.getLatitude(), userLocation.getLongitude()))
                        .zoom(20)
                        .build()));
            }
        });

I tried that and it works fine for me. Let me know if it is unclear, and hope it helps.

enter image description here

Upvotes: 2

Related Questions