1

I'm unable to make my custom marker in an Android App Rotate when using Google Maps API v2. I want to show the rotation like it occurs in the Uber App. I've set the flat property on the Marker, but it doesn't help. Following is the snippet

Marker marker = map.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.vehicle_marker)).flat(true).anchor(0.5f,0.5f));
Anoop M Maddasseri
  • 10,213
  • 3
  • 52
  • 73
AnupamChugh
  • 1,779
  • 1
  • 25
  • 36

2 Answers2

5

You can do it by using devices bearing or follow this tutorial.

Create a marker which is is perfect for bearing updates.

private Marker marker;

// Create this marker only once; probably in your onMapReady() method
marker = mGoogleMap.addMarker(new MarkerOptions()
        .position(new LatLng(myLatitude, myLongitude))
        .flat(true));

Get the bearing updates by using getBearing() method from Location object

  if (mLastLocation.hasBearing()) {
     marker.setRotation(mLocation.getBearing());
    }
     //if following the linked tutorial
    // marker.setRotation((float) azimuth);

Aware about this also when you using it.

Community
  • 1
  • 1
Anoop M Maddasseri
  • 10,213
  • 3
  • 52
  • 73
0

You could try like this

Marker marker = map.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.vehicle_marker)).flat(true).anchor(0.5f,0.5f).rotation(180));
Nigam Patro
  • 2,760
  • 1
  • 18
  • 33