android - Android:标记以超延迟添加到地图框
问题描述
我在我的 android 应用程序中使用地图框。初始化地图框后,我想在长按地图框时添加标记,因此按照官方网站的顺序,我将markerview依赖项添加到应用程序gradle:
dependencies {
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-markerview-v7:0.2.0'
}
然后我实现MapboxMap.OnMapLongClickListener
并覆盖onMapLongClick
.
当 mapview 准备好时,我启用enableLocationComponent
并创建markerViewManager
和设置 map long click listener
。
mapView.getMapAsync(mapboxMap -> {
this.mapboxMap = mapboxMap;
mapboxMap.setStyle(Style.MAPBOX_STREETS, style -> {
createCustomAnimationView();
moveTo(home_longitude, home_latitude, home_zoom);
enableLocationComponent();
markerViewManager = new MarkerViewManager(mapView, mapboxMap);
mapboxMap.addOnMapLongClickListener(this);
createCustomAnimationView();
});
});
最后在onMapLongClick
覆盖的方法中,我创建了一个 imageview 并添加到 markerViewManager。
@Override
public boolean onMapLongClick(@NonNull LatLng point) {
ImageView imageView = new ImageView(requireContext());
imageView.setLayoutParams(new RelativeLayout.LayoutParams(
(int) Measurement.convertDpToPixel(32, requireContext()),
(int) Measurement.convertDpToPixel(32, requireContext())));
imageView.setImageResource(R.drawable.location_ic);
MarkerView markerView = new MarkerView(new LatLng(point.getLatitude(), point.getLongitude()), imageView);
markerViewManager.addMarker(markerView);
return false;
}
当我运行应用程序并长按屏幕时:
第一个问题:location_ic出现在屏幕的顶部和左侧,一秒钟或更长时间后,图标放置在正确的位置
其他问题:当我移动地图时,这些标记保持固定并且不随地图移动,但在一秒钟或更长时间后放置在正确的位置。
我希望我已经解释清楚了,但如果你不明白我上传了一个小视频!!!
我的视频
解决方案
经过几天和googleing,我终于决定使用SymbolManager
在mapbox上添加标记:
只需添加:
dependencies {
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v7:0.5.0'
}
到 app gradle,然后onMapReady
像下面这样初始化插件:
symbolManager = new SymbolManager(mapView, mapboxMap,style);
symbolManager.setIconAllowOverlap(true);
symbolManager.setTextAllowOverlap(true);
并使用:
symbolManager.create(new SymbolOptions()
.withLatLng(point)
.withIconImage(IMAGE_MARKER_DEFAULT));
我希望它会有所帮助。
推荐阅读
- html - 在 Gmail 电子邮件中使用 Flex
- php - preg_match:修复了在评论框中阻止 https:// URL 链接的问题
- d3.js - d3.enter() 不是函数
- python - TypeError: unhashable type: 'list' while loading pre-trained ResNet in Tensorflow?
- python - 无法从应用程序访问站点包中的 python 安装包
- r - ggplot2 条形图 - 如何指定条形的 x 轴位置?
- c# - 如何从 Amazon Cloudwatch 获取公制单位?
- java - 授权谷歌日历而不重定向到登录页面
- java - Jersey 客户端总是抛出 400 Bad Request
- angular - 如何在 ngfor 中过滤选项