1

I am creating android apps which can show the route that generated from pgRouting, and return geojson file.

I already can draw the polyline on the web with mapbox-gl js with this code:

var geojson = {
          "type": "FeatureCollection",
          "features": []
        };

for(var i=0; i<data[0].length - 1; i++)
        {
            $json = JSON.parse(data[0][i]['json']);
            geojson.features.push($json);
        }

map.addLayer({
                        "id": "rute",
                        "type": "line",
                        "source": {
                            "type": "geojson",
                            "data": geojson
                        },
                        "layout": {
                            "line-join": "round",
                            "line-cap": "round"
                        },
                        "paint": {
                            "line-color": "#009688",
                            "line-width": 3
                        }
                    });

and the result is good like this:

enter image description here

But, when i draw the polyline on android with this code:

private ArrayList<LatLng> latLngs = new ArrayList<>();
for(int i=0; i<array_geocoordinate.length(); i++)
                            {
                                String[] koordinat = array_geocoordinate.get(i).toString().split(",");
                                LatLng koordinat_baru = new LatLng(Double.valueOf(koordinat[1].split("\\]")[0]), Double.valueOf(koordinat[0].split("\\[")[1]));
                                    Log.d(koordinat[0].split("\\[")[1] + ",", koordinat[1].split("\\]")[0]);
                                    latLngs.add(koordinat_baru);
                            }

map.addPolyline(new PolylineOptions()
                        .addAll(latLngs)
                        .color(Color.parseColor("#3bb2d0"))
                        .width(2));

The line of route become like this:

enter image description here

There're many polylines that draw incorrectly, how to fix that?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.