android - MapView 未正确显示
问题描述
我在androidMapView
里面使用。RecycleView
这是我的xml
代码:
<com.google.android.gms.maps.MapView
android:id="@+id/map_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
和:
private fun initializeMap() {
val mapView : MapView = binding.root.findViewById(R.id.map_view)
mapView?.let {
mapView.onCreate(null)
mapView.getMapAsync(this)
}
}
override fun onMapReady(map: GoogleMap?) {
MapsInitializer.initialize(fragment.context)
googleMap = map
googleMap?.let {
it.setOnMapLoadedCallback { this }
it.setOnMapClickListener { this }
it.uiSettings.setAllGesturesEnabled(false)
it.uiSettings.isZoomControlsEnabled = false
}
}
override fun onMapLoaded() {
}
override fun onMapClick(p0: LatLng?) {
}
出现的地图如下
tp 需要很长时间才能出现,也没有直接出现,我滚动了很多
还有方法onMapLoaded()
并且onMapClick()
不调用
解决方案
这是我的 map.xml 文件
<com.google.android.gms.maps.MapView android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android" />
这是java类
public class map extends Fragment implements OnMapReadyCallback {
GoogleMap mMap;
private MapView mapView;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.map,null);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
LatLng ahmedabad = new LatLng(23.022505, 72.571365);
BitmapDescriptor icon = BitmapDescriptorFactory.fromResource(R.drawable.icons8fiat50060);
MarkerOptions markerOptions = new MarkerOptions().position(ahmedabad)
.title("Current Location")
.snippet("Thinking of finding some thing...")
.icon(icon);
googleMap.addMarker(markerOptions);
mMap.getUiSettings().setZoomControlsEnabled(true);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(ahmedabad,30f));
}
这很容易,我认为这对您有帮助。
推荐阅读
- java - JWT 访问令牌不会在每个令牌授权调用上生成
- php - 在表单侦听器中修改查询构建器
- django - 如何覆盖 Django 2.0 中的 autocomplete_fields 样式?
- swift - 在 Swift 4 中创建简单的倒计时日期应用程序时出错
- c++ - “错误'SetWindowTextA':不是'CStatic'和char *fgets(char *,int,FILE *)的成员:无法将参数1从'TCHAR'转换为'char *'
- android - Android 应用程序崩溃,在 logcat 中查找原因
- android - 将图像从 android 应用程序发送到 localhost
- php - 生产迁移新鲜
- php - 为什么该按钮不仅对第一行有效,也不能发布任何值?
- sql - 如何根据树中的父节点获取自引用的表树结构?