如何从 Android 中的经纬度列表创建 Mapbox 热点和热图?
How to create Mapbox hotspots and heatmap from lat-long list in Android?
我有一个数据库 table 包含我需要在 Mapbox 地图上显示为热点或热图的经纬度数据。
我查看了 hotspots and heatmaps 的官方示例,但他们都从 URL(geojson 格式)加载数据。
我需要对他们的示例代码进行哪些更改(Java 并且未弃用),因此 hotspot/heatmap 数据是从我的 LatLng[=19 数组中加载的=] 对象代替?
要将 LatLng 对象转换为要素,请使用:
var feature = Feature.fromGeometry(Point.fromLngLat(longitude, latitude))
并将它们添加到功能列表中。然后你可以创建一个 FeatureCollection 的实例:
public static FeatureCollection fromFeatures(@NonNull List<Feature> features)
最后,GeoJsonSource 中有一个构造函数,您可以在其中使用 FeatureCollection 而不是 URI:
public GeoJsonSource(String id, FeatureCollection features, GeoJsonOptions options)
List<LatLng> latLngListFromDatabase = new ArrayList<>();
List<Feature> featureList = new ArrayList<>();
for (LatLng latLngObject : latLngListFromDatabase) {
featureList.add(Feature.fromGeometry(Point.fromLngLat(latLngObject.getLongitude(), latLngObject.getLatitude())));
}
loadedMapStyle.addSource(new GeoJsonSource("source-id", FeatureCollection.fromFeatures(featureList)));
我有一个数据库 table 包含我需要在 Mapbox 地图上显示为热点或热图的经纬度数据。
我查看了 hotspots and heatmaps 的官方示例,但他们都从 URL(geojson 格式)加载数据。
我需要对他们的示例代码进行哪些更改(Java 并且未弃用),因此 hotspot/heatmap 数据是从我的 LatLng[=19 数组中加载的=] 对象代替?
要将 LatLng 对象转换为要素,请使用:
var feature = Feature.fromGeometry(Point.fromLngLat(longitude, latitude))
并将它们添加到功能列表中。然后你可以创建一个 FeatureCollection 的实例:
public static FeatureCollection fromFeatures(@NonNull List<Feature> features)
最后,GeoJsonSource 中有一个构造函数,您可以在其中使用 FeatureCollection 而不是 URI:
public GeoJsonSource(String id, FeatureCollection features, GeoJsonOptions options)
List<LatLng> latLngListFromDatabase = new ArrayList<>();
List<Feature> featureList = new ArrayList<>();
for (LatLng latLngObject : latLngListFromDatabase) {
featureList.add(Feature.fromGeometry(Point.fromLngLat(latLngObject.getLongitude(), latLngObject.getLatitude())));
}
loadedMapStyle.addSource(new GeoJsonSource("source-id", FeatureCollection.fromFeatures(featureList)));