我在android中的MapView
内使用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()
也不会调用
有人可以帮忙吗?
答案 0 :(得分:0)
在设置it.uiSettings.setAllGesturesEnabled(false)
和it.uiSettings.isZoomControlsEnabled = false
时,请在Lite Mode中使用MapView
:
<com.google.android.gms.maps.MapView
android:id="@+id/map_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:cameraZoom="<ZOOM>"
map:mapType="normal"
map:liteMode="true">
Here,您可以在MapView
和here RecyclerView
布局设置中找到使用MapView
的官方示例:
<!-- MapView in lite mode. Note that it needs to be initialised programmatically before it can be used. --> <com.google.android.gms.maps.MapView android:id="@+id/lite_listrow_map" android:layout_width="match_parent" android:layout_height="150dp" map:liteMode="true" map:mapType="none" />
答案 1 :(得分:0)
这是我的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));
}
} 这很容易,我认为这对您有帮助。