mapbox-gl-native icon indicating copy to clipboard operation
mapbox-gl-native copied to clipboard

[Android] DirectionsRoute to LatLng conversation error

Open P-Zenker opened this issue 9 years ago • 1 comments

Hey,

Platform: Android Mapbox SDK version: 5.0.2

Steps to trigger behavior

1.

MapboxDirections client = new MapboxDirections.Builder()
                .setOrigin(origin)
                .setDestination(destination)
                .setProfile(DirectionsCriteria.PROFILE_DRIVING)
                .setAccessToken(Mapbox.getAccessToken())
                .setOverview(DirectionsCriteria.OVERVIEW_FULL)
                .setSteps(true)
                .build();

2.

LineString lineString = LineString.fromPolyline(route.getGeometry(), Constants.OSRM_PRECISION_V5);
List<Position> coordinates = lineString.getCoordinates();

3.

LatLng[] points = new LatLng[coordinates.size()];
for (int i = 0; i < coordinates.size(); i++) {
  points[i] = new LatLng(
    coordinates.get(i).getLatitude(),
    coordinates.get(i).getLongitude());
}
for(int i = 0; i < points.length; i++){
 Log.d(TAG, "Point i = " + i + "  " + points[i]);
}

Expected behavior

Point i = 0  LatLng [latitude=53.874291, longitude=10.683888, altitude=0.0]
Point i = 1  LatLng [latitude=53.874065, longitude=10.683222, altitude=0.0]

Actual behavior

W/Position: Latitude value seems to be out of range (found: 538.742910, expected: [-90, 90]). Did you accidentally reverse the longitude/latitude order?
W/Position: Latitude value seems to be out of range (found: 538.740650, expected: [-90, 90]). Did you accidentally reverse the longitude/latitude order?

Point i = 0  LatLng [latitude=538.74291, longitude=106.83888, altitude=0.0]
Point i = 1  LatLng [latitude=538.74065, longitude=106.83222, altitude=0.0]

Best regards, Patrick

P-Zenker avatar Apr 07 '17 08:04 P-Zenker

Hey Patrick, changing the precision while converting the polyline to a linestring should fix this. More specifically, change this:

LineString lineString = LineString.fromPolyline(route.getGeometry(), Constants.OSRM_PRECISION_V5);

to this:

LineString lineString = LineString.fromPolyline(route.getGeometry(), Constants.PRECISION_6);

cammace avatar Apr 07 '17 14:04 cammace