Turn (rotate)marker position based on direction over the route
Asked Answered
V

1

9

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

Vauban answered 16/6, 2014 at 9:36 Comment(1)
Did you got any solution? can you share a code with me?Paynter
A
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;

    }
Aframe answered 12/1, 2016 at 12:38 Comment(4)
I am working on a similar project. Why is oldlong assigned newlong?Donalddonaldson
where did you call this method?Paynter
@Ashish Patil I used the code provided by you ,but everytime I get bearing value =0.0 .Can you please help ?Beautiful
@N.Droid Call on Location UpdateAframe

© 2022 - 2024 — McMap. All rights reserved.