1

I need my app to fetch the direction using Bearing and put it on the map with my custom Icon facing the fetched direction. Right now, it shows the wrong direction. I need to make it work like Uber or Lyft 's car icon rotation plotted on Map. Please Suggest if my approach is correct or wrong. Currently I am fetching direction and displaying icon on the same app for testing.

This is what I am doing:

@Override
public void onLocationChanged(Location location) {
    LatLng latlng = new LatLng(location.getLatitude(), location.getLongitude());
    CameraPosition cameraPOsition = new CameraPosition.Builder().target(latlng).zoom(15f).build();
    MarkerOptions markerOptions = new MarkerOptions().flat(true).position(new LatLng(location.getLatitude(), location.getLongitude()));
    googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPOsition));
    Marker m = googleMap.addMarker(markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.car)).rotation(location.getBearing()).anchor(0.5f, 0.5f));
    m.setPosition(new LatLng(location.getLatitude(), location.getLongitude()));
}
4

0 回答 0