android - Route overlay cuts through roads - Mapbox -


this code copied https://www.mapbox.com/android-sdk/examples/directions/ doesn't display overlay on road, it'll cut through streets though specified criteria profile_driving:

private void getroute(position origin, position destination) throws servicesexception {          mapboxdirections client = new mapboxdirections.builder()                 .setorigin(origin)                 .setdestination(destination)                 .setprofile(directionscriteria.profile_driving)                 .setaccesstoken(commonresource.mapbox_access_token)                 .build();          client.enqueuecall(new retrofit2.callback<directionsresponse>() {             @override             public void onresponse(call<directionsresponse> call, response<directionsresponse> response) {                 // can generic http info response                 if (response.body() == null) {                     return;                 }                  currentroute = response.body().getroutes().get(0);                 drawroute(currentroute);             }              @override             public void onfailure(call<directionsresponse> call, throwable t) {                                     toast.maketext(mainactivity.this, "error: " + t.getmessage(), toast.length_short).show();             }         });     }      private void drawroute(directionsroute route) {         // convert linestring coordinates latlng[]         linestring linestring = linestring.frompolyline(route.getgeometry(), constants.osrm_precision_v5);         list<position> coordinates = linestring.getcoordinates();         latlng[] points = new latlng[coordinates.size()];         (int = 0; < coordinates.size(); i++) {             points[i] = new latlng(                     coordinates.get(i).getlatitude(),                     coordinates.get(i).getlongitude());         }          // draw points on mapview         map.addpolyline(new polylineoptions()                 .add(points)                 .color(color.parsecolor("#009688"))                 .width(5));     } 

enter image description here

correct answer: providing points, didn't realize happening until saw entire route. you'll need setoverview full. done when building directions request, example:

mapboxdirections client = new mapboxdirections.builder()   .setorigin(origin)   .setdestination(destination)   .setprofile(directionscriteria.profile_cycling)   .setoverview(directionscriteria.overview_full) // line needs added.   .setaccesstoken(<access token>)   .build(); 

previous troubleshooting: which version of mapobx android services using? edit question entire class or link on github. i'm not seeing issues looking @ code. troubleshooting on end, i'd recommend changing osrm_precision_v5 , check size of points array see things go wrong.

i'll edit answer once additional information's provided.

edit: no need change encoding constant if using mapbox directions v5. instead can make sure importing correct classes, work off this example in demo app. if still having issues, mentioned below, please post additional code can provide, snippet in question pretty identical 1 found on our website.


Comments