0

I am developing an Android application which has a turn-by-turn navigation between two locations. However, I've been struggling to make the navigation smooth.

I call Directions Api from Google API to retrieve the route and I've already displayed it on the map. When switching to turn-by-turn navigaton I just set the marker to the new location (also animating the marker) using location manager (using both course and fine location). Everything works fine although the gps and network provider have some innacurate locations as shown in the image in the link below.

Although does errors sometimes aren't too big ( for example the location is set at the sidewalk next to the street), I need the marker to be always following the polyline as long as the user is following the route, otherwise it will have to recalculate the route. Furthermore, as I calculate the bearing of the icon through the previous location and the new one, sometimes the icon does weird things.

I don't want to use any external library as the majority aren't free and the application won't be for personal use in a future. My first idea was to check if the distance of my updated location to the polyline was bigger than x (say 5) in order to detect those errors. However, my application has to recalculate the route so this isn't a valid option. I've read about Kalman algorithm to detect errors, but people say that gps internally already filters location using that algorithm.

So I need advice in order to fix those innacurate locations and make a smooth navigation as Mapbox or Google Maps or Uber does.

Link to image: https://ibb.co/n511We

Yellow line indicates the route I made and the purple circles are the inaccurate locations.

Michael Dodd
  • 10,102
  • 12
  • 51
  • 64
  • The locations will always be somewhat "imperfect". GPS locations may vary several meters or even several tens of meters from the actual location, so you'll need to allow some tolerance, or your app will be re-calculating the route all the time. As for the visual side: probably there's some way that you can use the [Snap to Roads](https://developers.google.com/maps/documentation/roads/snap) feature in the Roads API. As in [How to Add Snap to Roads Google Map in Android Studio](https://stackoverflow.com/questions/35472005/how-to-add-snap-to-roads-google-map-in-android-studio). – Markus Kauppinen Sep 21 '18 at 14:03
  • @MarkusKauppinen I can't see how can I use Snaps to Roads to make a turn-by-turn navigation (visual side), since I've read that this API returns a path given some coordinates, similar to Directions API. Should I make an Api request every time with my actual location to receive the latitude and longitude or how? Thank you – Enricrp Rubio Sep 21 '18 at 16:08
  • I'm not actually familiar with it myself. Maybe it's not really suitable for real-time tracking. Anyway, that's the mechanism to have a visually "perfect" location on a map. – Markus Kauppinen Sep 21 '18 at 16:49

0 Answers0