MapBox 用户位置图标 (Android)
MapBox User Location Icon (Android)
我的 Android 应用程序使用 MapBox,我需要修改用于指示当前用户位置和方向的标准蓝色 "dot"。
我发现这个帖子表明过去的 MapBox Android API 提供了修改用户位置图标的方法:
https://github.com/mapbox/mapbox-android-sdk-legacy/issues/717
线程提到了这些方法:
mapView.getUserLocationOverlay().setDirectionArrowBitmap();
mapView.getUserLocationOverlay().setPersonBitmap();
最新的MapBox Android SDK不显示这些方法。有谁知道这些方法的替代方法或修改用户位置图标的替代方法?
MapBox 回应了澄清这些方法的替代品的请求,说:
As for changing location of a custom Marker to show movement, the best bet is to add and remove Markers when you need to show progress. Depending on how quickly you need to refresh the location, this approach might look a bit choppy, but it is the best workaround at this point. This would be done via
MapView.addMarker()
和
MapView.removeAnnotation()
这不是一个理想的解决方案,但现在应该可以完成工作。
我已经添加了一个公交车图标,你可以随意更改它。
@SuppressWarnings({"MissingPermission"})
private void enableLocationComponent(@NonNull Style loadedMapStyle) {
// Check if permissions are enabled and if not request
if (PermissionsManager.areLocationPermissionsGranted(mainActivity)) {
// Activate the MapboxMap LocationComponent to show user location
// Adding in LocationComponentOptions is also an optional parameter
locationComponent = mapboxMap.getLocationComponent();
locationComponent.activateLocationComponent(mainActivity, loadedMapStyle);
locationComponent.setLocationComponentEnabled(true);
// Create and customize the LocationComponent's options
LocationComponentOptions customLocationComponentOptions = LocationComponentOptions.builder(getActivity())
.foregroundDrawable(R.drawable.bus)
.build();
// Get an instance of the component
locationComponent = mapboxMap.getLocationComponent();
LocationComponentActivationOptions locationComponentActivationOptions =
LocationComponentActivationOptions.builder(getActivity(), loadedMapStyle)
.locationComponentOptions(customLocationComponentOptions)
.build();
// Activate with options
locationComponent.activateLocationComponent(locationComponentActivationOptions);
// Set the component's camera mode
locationComponent.setCameraMode(CameraMode.TRACKING);
// IconFactory iconFactory = IconFactory.getInstance(getActivity());
// mapboxMap.addMarker(new MarkerOptions().icon(iconFactory.fromResource(R.drawable.bus)));
} else {
permissionsManager = new PermissionsManager(this);
permissionsManager.requestLocationPermissions(mainActivity);
}
}
标记表示地图上的单个位置。您可以通过更改默认颜色或用自定义图像替换标记图标来自定义标记。信息 windows 可以为标记提供额外的上下文。
MarkerView markerView = new MarkerView(new LatLng(LAT,LONG), customView);
markerViewManager.addMarker(markerView);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(MapboxMap mapboxMap) {
MarkerViewManager markerViewManager = new MarkerViewManager(mapView, mapboxMap);
}
});
markerViewManager.removeMarker(markerView);
废话少说,让我们看看
好的,我们会检查一下
这里什么都没有。
如果你看到
你需要
我会检查并回复
现在你可以
别担心
@Volatile
synchronized intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK.or(Intent.FLAG_ACTIVITY_CLEAR_TASK)
// for Log
public static final String TAG = MyApplication.class.getSimpleName();
我的 Android 应用程序使用 MapBox,我需要修改用于指示当前用户位置和方向的标准蓝色 "dot"。
我发现这个帖子表明过去的 MapBox Android API 提供了修改用户位置图标的方法: https://github.com/mapbox/mapbox-android-sdk-legacy/issues/717
线程提到了这些方法:
mapView.getUserLocationOverlay().setDirectionArrowBitmap();
mapView.getUserLocationOverlay().setPersonBitmap();
最新的MapBox Android SDK不显示这些方法。有谁知道这些方法的替代方法或修改用户位置图标的替代方法?
MapBox 回应了澄清这些方法的替代品的请求,说:
As for changing location of a custom Marker to show movement, the best bet is to add and remove Markers when you need to show progress. Depending on how quickly you need to refresh the location, this approach might look a bit choppy, but it is the best workaround at this point. This would be done via
MapView.addMarker()
和
MapView.removeAnnotation()
这不是一个理想的解决方案,但现在应该可以完成工作。
我已经添加了一个公交车图标,你可以随意更改它。
@SuppressWarnings({"MissingPermission"})
private void enableLocationComponent(@NonNull Style loadedMapStyle) {
// Check if permissions are enabled and if not request
if (PermissionsManager.areLocationPermissionsGranted(mainActivity)) {
// Activate the MapboxMap LocationComponent to show user location
// Adding in LocationComponentOptions is also an optional parameter
locationComponent = mapboxMap.getLocationComponent();
locationComponent.activateLocationComponent(mainActivity, loadedMapStyle);
locationComponent.setLocationComponentEnabled(true);
// Create and customize the LocationComponent's options
LocationComponentOptions customLocationComponentOptions = LocationComponentOptions.builder(getActivity())
.foregroundDrawable(R.drawable.bus)
.build();
// Get an instance of the component
locationComponent = mapboxMap.getLocationComponent();
LocationComponentActivationOptions locationComponentActivationOptions =
LocationComponentActivationOptions.builder(getActivity(), loadedMapStyle)
.locationComponentOptions(customLocationComponentOptions)
.build();
// Activate with options
locationComponent.activateLocationComponent(locationComponentActivationOptions);
// Set the component's camera mode
locationComponent.setCameraMode(CameraMode.TRACKING);
// IconFactory iconFactory = IconFactory.getInstance(getActivity());
// mapboxMap.addMarker(new MarkerOptions().icon(iconFactory.fromResource(R.drawable.bus)));
} else {
permissionsManager = new PermissionsManager(this);
permissionsManager.requestLocationPermissions(mainActivity);
}
}
标记表示地图上的单个位置。您可以通过更改默认颜色或用自定义图像替换标记图标来自定义标记。信息 windows 可以为标记提供额外的上下文。
MarkerView markerView = new MarkerView(new LatLng(LAT,LONG), customView);
markerViewManager.addMarker(markerView);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(MapboxMap mapboxMap) {
MarkerViewManager markerViewManager = new MarkerViewManager(mapView, mapboxMap);
}
});
markerViewManager.removeMarker(markerView);
废话少说,让我们看看 好的,我们会检查一下 这里什么都没有。 如果你看到 你需要 我会检查并回复 现在你可以 别担心
@Volatile
synchronized intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK.or(Intent.FLAG_ACTIVITY_CLEAR_TASK)
// for Log
public static final String TAG = MyApplication.class.getSimpleName();