用户移动时 Mapbox 没有绘制图层
Mapbox did not draw Layer when user's moving
我正在制作一个 运行 应用程序并使用 Sdk mapbox。需求是当用户移动时,我需要从开始位置到最新位置绘制一层,
我试过这种方法,但没用
class LocationChangeListeningActivityLocationCallback internal constructor(activity: MapBoxActivity) : LocationEngineCallback<LocationEngineResult> {
private val activityWeakReference: WeakReference<MapBoxActivity> = WeakReference(activity)
override fun onSuccess(result: LocationEngineResult) {
val activity = activityWeakReference.get()
if (activity != null) {
val location = result.lastLocation ?: return
if (result.lastLocation != null) {
activity.mapBoxMap.locationComponent.forceLocationUpdate(result.lastLocation)
activity.listPoint.add(Point.fromLngLat(location.latitude, location.longitude))
activity.trackingLine()
}
}
}
override fun onFailure(exception: Exception) {
val activity = activityWeakReference.get()
if (activity != null) {
Toast.makeText(activity, exception.localizedMessage, Toast.LENGTH_SHORT).show();
}
}
}
var listPoint: ArrayList<Point> = ArrayList()
private var geoJson: GeoJsonSource = GeoJsonSource(LINE_SOURCE_ID)
fun trackingLine() {
mapBoxMap.getStyle {
geoJson.setGeoJson((Feature.fromGeometry(LineString.fromLngLats(listPoint))))
LogCat.d("Set new location in geoJSON")
}
}
private fun initDotLinePath(loadedMapStyle: Style) {
loadedMapStyle.addSource(geoJson)
loadedMapStyle.addLayerBelow(LineLayer(LAYER_ID_3, LINE_SOURCE_ID).withProperties(
PropertyFactory.lineColor(Color.parseColor("#F13C6E")),
PropertyFactory.lineCap(Property.LINE_CAP_ROUND),
PropertyFactory.lineJoin(Property.LINE_JOIN_ROUND),
PropertyFactory.lineWidth(4f)), "road-label")
}
请指出我的错误。非常感谢
activity.listPoint.add(Point.fromLngLat(location.latitude, location.longitude))
您的坐标顺序错误。
我正在制作一个 运行 应用程序并使用 Sdk mapbox。需求是当用户移动时,我需要从开始位置到最新位置绘制一层,
我试过这种方法,但没用
class LocationChangeListeningActivityLocationCallback internal constructor(activity: MapBoxActivity) : LocationEngineCallback<LocationEngineResult> {
private val activityWeakReference: WeakReference<MapBoxActivity> = WeakReference(activity)
override fun onSuccess(result: LocationEngineResult) {
val activity = activityWeakReference.get()
if (activity != null) {
val location = result.lastLocation ?: return
if (result.lastLocation != null) {
activity.mapBoxMap.locationComponent.forceLocationUpdate(result.lastLocation)
activity.listPoint.add(Point.fromLngLat(location.latitude, location.longitude))
activity.trackingLine()
}
}
}
override fun onFailure(exception: Exception) {
val activity = activityWeakReference.get()
if (activity != null) {
Toast.makeText(activity, exception.localizedMessage, Toast.LENGTH_SHORT).show();
}
}
}
var listPoint: ArrayList<Point> = ArrayList()
private var geoJson: GeoJsonSource = GeoJsonSource(LINE_SOURCE_ID)
fun trackingLine() {
mapBoxMap.getStyle {
geoJson.setGeoJson((Feature.fromGeometry(LineString.fromLngLats(listPoint))))
LogCat.d("Set new location in geoJSON")
}
}
private fun initDotLinePath(loadedMapStyle: Style) {
loadedMapStyle.addSource(geoJson)
loadedMapStyle.addLayerBelow(LineLayer(LAYER_ID_3, LINE_SOURCE_ID).withProperties(
PropertyFactory.lineColor(Color.parseColor("#F13C6E")),
PropertyFactory.lineCap(Property.LINE_CAP_ROUND),
PropertyFactory.lineJoin(Property.LINE_JOIN_ROUND),
PropertyFactory.lineWidth(4f)), "road-label")
}
请指出我的错误。非常感谢
activity.listPoint.add(Point.fromLngLat(location.latitude, location.longitude))
您的坐标顺序错误。