问题
I use MapBox for my Android App, and I need to modify the standard blue "dot" that is used to indicate the current user location and orientation.
I found this thread indicating that past MapBox Android APIs offered methods to modify the User Location Icon: https://github.com/mapbox/mapbox-android-sdk-legacy/issues/717
The thread mentions these methods:
mapView.getUserLocationOverlay().setDirectionArrowBitmap();
mapView.getUserLocationOverlay().setPersonBitmap();
The newest MapBox Android SDK does not show these methods. Does anyone know replacements for these methods or alternatives to modifying the User Location Icon?
The maven archive is here: http://grepcode.com/file/repo1.maven.org/maven2/com.mapbox.mapboxsdk/mapbox-android-sdk/0.7.4/com/mapbox/mapboxsdk/overlay/UserLocationOverlay.java#UserLocationOverlay.setDirectionArrowBitmap%28com.mapbox.mapboxsdk.overlay.Bitmap%29
回答1:
MapBox responded to a request to clarify replacements for these methods, saying:
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()
and
MapView.removeAnnotation()
That is not an ideal solution, but it should get the job done for now.
回答2:
Markers indicate single locations on the map. You can customize your markers by changing the default color, or replacing the marker icon with a custom image. Info windows can provide additional context to a marker.
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);
let us put them together to work
Enough talk, let us see some ok we'll check it There's nothing here, yet. If you see you'll need I'll check and reply Now you can don't worry
@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();
回答3:
I have Added a bus icon and you can change it as You Want.
@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);
}
}
来源:https://stackoverflow.com/questions/33644362/mapbox-user-location-icon-android