VTM: Rotate map according to riding

377 views
Skip to first unread message

Adi Barda

unread,
Jun 25, 2018, 10:41:30 AM6/25/18
to mapsforge-dev
Hi Everyone,
I'm in the process of integrating VTM/MapsForge in my Android application (AdvRider WD).
I have a requirement of rotating the map to the direction of the riding (I have previous and current GPS locations)
What is the best way to do that in VTM? Is there an automatic way for doing so?

Thanks,
Adi

Emux

unread,
Jun 25, 2018, 1:28:09 PM6/25/18
to mapsfo...@googlegroups.com
Can check the viewport various setters, e.g.:

mapView.map().viewport().setRotation(degree);

--
Emux

Adi Barda

unread,
Jun 25, 2018, 11:41:48 PM6/25/18
to mapsforge-dev
Thanks, I'm a little confused between setting the MapPosition bearing and rotating the map.
For google maps the below formula for calculating the bearing according to 2 Lat/Lng works for me:

private double getBearing(double lat1, double lng1, double lat2, double lng2) {
double dLon = (lng2 - lng1);
double y = Math.sin(dLon) * Math.cos(lat2);
double x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1)
* Math.cos(lat2) * Math.cos(dLon);
double brng = Math.toDegrees((Math.atan2(y, x)));

return brng;
}

However, when I set this bearing number to the MapPosition's setBearing() just before using it with:  animator().animateTo
It doesn't work as expected. There is a difference between Google maps and VTM when using the bearing.
I always want the map to point (rotate) to the direction which I'm heading

Adi Barda

unread,
Jun 26, 2018, 2:07:55 AM6/26/18
to mapsforge-dev
OK, I think I solved the problem by multiplying by -1. Maybe VTM bearing is probably works the opposite from Google maps  
Reply all
Reply to author
Forward
0 new messages