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
If you have a bearing, you can set the rotation of the marker using MarkerOptions. rotation() : mMap. addMarker(new MarkerOptions() .
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.
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.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With