0

Apologies in advance if this has been answered. I can not find anything online or in the repository pointing to my issue.

I have a ArrayList<Position> which is holding my line sting.

This display's fine when drawing it with addPolyline

I would like to style the line so I switched to using a line layer. However.

The line no long appears any where close to the correct location. The location is in Cumbria, England, but is drawn of the coast of Somalia.

I have tried to output the coordinates after each transformation and they all appear okay. I can not work out how to inspect the source

Log.d("Tracing 1", route.toString())

val lineString = LineString.fromCoordinates(route)

Log.d("Tracing 2", lineString.coordinates.toString())

val feature = Feature.fromGeometry(lineString)

Log.d("Tracing 3", feature.geometry.coordinates.toString())

val featureCollection = FeatureCollection.fromFeatures(
        arrayOf(feature))

val geoJsonSource: Source = GeoJsonSource("line-source", featureCollection)
mapboxMap.addSource(geoJsonSource)

val debugSource = mapboxMap.getSource("line-source") as GeoJsonSource
Log.d("Tracing 4", debugSource.toString())

val lineLayer = LineLayer("linelayer", "line-source")

lineLayer.setProperties(
        PropertyFactory.lineDasharray(arrayOf(0.01f, 2f)),
        PropertyFactory.lineCap(LINE_CAP_ROUND),
        PropertyFactory.lineJoin(LINE_JOIN_ROUND),
        PropertyFactory.lineWidth(5f),
        PropertyFactory.lineColor(Color.parseColor("#e55e5e"))
)

mapboxMap.addLayer(lineLayer)

val cameraPosition = CameraPosition.Builder()
        .target(LatLng(route[0].latitude, route[0].longitude))
        .build()

mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition))

The log cat output showing that the Logs are all the same is here.

10-05 20:52:37.162 11449-11449/com.xxx.xxx D/Tracing 1: [Position [longitude=54.82269833333333, latitude=-2.8017883333333335, altitude=NaN], Position [longitude=54.82289833333333, latitude=-2.80173, altitude=NaN], Position [longitude=54.823098333333334, latitude=-2.8015583333333334, altitude=NaN], Position [longitude=54.8233, latitude=-2.8012799999999998, altitude=NaN], Position [longitude=54.82339833333334, latitude=-2.801078333333333, altitude=NaN], Position [longitude=54.82379833333333, latitude=-2.8007583333333335, altitude=NaN], Position [longitude=54.8241, latitude=-2.8004183333333335, altitude=NaN]]

10-05 20:52:37.172 11449-11449/com.xxx.xxx D/Tracing 2: [Position [longitude=54.82269833333333, latitude=-2.8017883333333335, altitude=NaN], Position [longitude=54.82289833333333, latitude=-2.80173, altitude=NaN], Position [longitude=54.823098333333334, latitude=-2.8015583333333334, altitude=NaN], Position [longitude=54.8233, latitude=-2.8012799999999998, altitude=NaN], Position [longitude=54.82339833333334, latitude=-2.801078333333333, altitude=NaN], Position [longitude=54.82379833333333, latitude=-2.8007583333333335, altitude=NaN], Position [longitude=54.8241, latitude=-2.8004183333333335, altitude=NaN]]

10-05 20:52:37.172 11449-11449/com.xxx.xxx D/Tracing 3: [Position [longitude=54.82269833333333, latitude=-2.8017883333333335, altitude=NaN], Position [longitude=54.82289833333333, latitude=-2.80173, altitude=NaN], Position [longitude=54.823098333333334, latitude=-2.8015583333333334, altitude=NaN], Position [longitude=54.8233, latitude=-2.8012799999999998, altitude=NaN], Position [longitude=54.82339833333334, latitude=-2.801078333333333, altitude=NaN], Position [longitude=54.82379833333333, latitude=-2.8007583333333335, altitude=NaN], Position [longitude=54.8241, latitude=-2.8004183333333335, altitude=NaN]]

10-05 20:52:37.182 11449-11449/com.xxx.xxx D/Tracing 4: com.mapbox.mapboxsdk.style.sources.GeoJsonSource@9d382a28

The question I have is; am I doing something wrong is there something I am missing?

Thanks

Joe Doherty
  • 3,778
  • 2
  • 31
  • 37

1 Answers1

6

For MapBox, you have to supply the latitude and longitude in reversed order. Your problem is that you have switched up the longitude and latitude coordinates for each point.

Daniel Zolnai
  • 16,487
  • 7
  • 59
  • 71
  • Wow! That was quick and correct. Thank you. I was previously pulling them out of the database as LatLng and changed to Position for GeoJSON and never even saw the arguments differed. That had me stumped. Thanks again. – Joe Doherty Oct 05 '17 at 20:20
  • I was wondering would it be possible to do this on the fly somehow or am I stuck writing an update function to reverse all those one by one? – SebastianG Jun 04 '19 at 10:05