8

I've a route created along with a polyline over google maps api v2 (Android). My custom marker moves along the route which i achieved by creating a thread. I also get the maneuvers (turn-left, turn-right, etc).

Now as my marker starts moving (a car icon), i want it to turn and navigate through the route. I did manage to rotate it, however i want an accurate solution for this query. right now i hard coded the angles and thus rotating my marker along with the " setRoation() method ". However the rotation isn't as it should be and i cannot get its dynamic angles.

Please Help ! Thanks in advance

LEE
  • 3,335
  • 8
  • 40
  • 70

1 Answers1

4

Hey see following code for rotate marker as per location

 double oldlat = 19.180237, oldlong = 72.855415;
    double newlat = 19.180237, newlong = 72.855415;

    public void rotatemarker() {
        Location prevLoc = new Location("service Provider");
        prevLoc.setLatitude(oldlat);
        prevLoc.setLongitude(oldlong);
        Location newLoc = new Location("service Provider");
        newLoc.setLatitude(newlat);
        newLoc.setLongitude(newlong);
        bearing = prevLoc.bearingTo(newLoc);
        map.clear();
        map.addMarker(new MarkerOptions()
                .position(new LatLng(newlat, newlong))
                .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher))
                .anchor(0.5f, 0.5f)
                .rotation(bearing)
                .flat(true));


        oldlong = newlong;

    }
Ashish Patil
  • 374
  • 4
  • 20