1

Now I am working on mobile application Which fetches the gps location in certain intervals send location data to server. The server draw Google route map based in this information.

Please help me solve the following scenario

Sometime the gps coordinates marked on the Opposite route actually traveled and make the route Completely error.

For example I travelled on a route like this (On google map)

enter image description here

But I get map like (On google map)

enter image description here

The point B is fetched/Marked on the parallel road

How can i solve this problem?

Stack User 5674
  • 1,548
  • 1
  • 20
  • 44

1 Answers1

0

try alexander library for route drow

compile 'com.github.jd-alexander:library:1.1.0'

example:

private void startRouting() {

        
        LatLng  origin = new LatLng(18.01455, -77.499333);
        LatLng destination = new LatLng(18.0145600, -77.491333);
        Routing routing = new Routing.Builder()
                .travelMode(Routing.TravelMode.DRIVING)
                .alternativeRoutes(false)
                .withListener(new RoutingListener() {
                    @Override
                    public void onRoutingFailure(RouteException e) {
                        Log.e("onRoutingFailure: ", e.getMessage());
                    }

                    @Override
                    public void onRoutingStart() {

                    }

                    @Override
                    public void onRoutingSuccess(ArrayList<Route> routes, int shortestRouteIndex) {
                        if (routes != null && routes.size() > 0) {
                            for (Route route : routes) {
                                List<LatLng> latlngs = route.getPoints();
                                try {

                                    Random rnd = new Random();
                                    int color = Color.argb(200, rnd.nextInt(256), rnd.nextInt(256), 0);
/*                                    int color1 = Color.argb(225, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
                                    int color2 = Color.argb(225, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
                                    int color3 = Color.argb(225, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));*/
                                    mMap.addPolyline(new PolylineOptions().addAll(latlngs).color(color).width(12.0f));

                                } catch (Exception e) {
                                    e.printStackTrace();
                                    Log.e("onRoutingSuccess: ", e.getMessage());
                                    Toast.makeText(MainActivity.this, "An internal error occurred!", Toast.LENGTH_SHORT).show();
                                }
                            }
                            //showBottomSheet(routes.get(shortestRouteIndex));
                        }
                    }

                    @Override
                    public void onRoutingCancelled() {
                        Log.e("onRoutingCancelled: ", "Routing cancelled");
                    }
                })
                .waypoints(origin, destination)
                .build();
        routing.execute();


    }
Nur Gazi
  • 47
  • 2