Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 646
Abhilash Avatar asked Jun 16 '14 09:06

Abhilash


People also ask

How do you rotate a marker bus according to direction?

If you have a bearing, you can set the rotation of the marker using MarkerOptions. rotation() : mMap. addMarker(new MarkerOptions() .

What is a direction marker on a map?

Some marker shapes, for example arrows, indicate directions. If you, in a map chart marker layer, rotate such markers, you can visualize directions of motions. What you need is a column that contains values that can be interpreted as degrees. The rotation of the markers can be made clockwise or counter-clockwise.

How to rotate angle on google maps?

Using mouse and keyboard gestures You can adjust tilt and rotation using the mouse and keyboard: Using the mouse, hold down the shift key, then click and drag the mouse up and down to adjust tilt, right and left to adjust heading.


1 Answers

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;

    }
like image 198
Ashish Patil Avatar answered Nov 11 '22 17:11

Ashish Patil