1
只是想知道如何将经度和纬度绑定到com.google.android.gms.maps.MapView
。感觉就像它没有公开任何布局属性。将位置绑定到MVVM中的MapView
只是想知道如何将经度和纬度绑定到com.google.android.gms.maps.MapView
。感觉就像它没有公开任何布局属性。将位置绑定到MVVM中的MapView
找到答案我自己。
只需要创建用@BindingAdapter注解的静态方法。 喜欢的东西:
@BindingAdapter("app:latLong")
public static void bindLocationToMap(MapView mapView, LatLng latLong) {
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLong, 10);
mapView.animateCamera(cameraUpdate);
}
而且使用属性上述布局定义:
...
<com.google.android.gms.maps.MapView android:id="@+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:location="@{latLong} />
...
不过是''com.google.android.gms.maps.MapView使用地图的正确方法?我的意思是,每个文档都会告诉你使用一个片段,而且我想知道这是否是一种废弃的方式。 – jturolla
我好奇jturolla也问。但我明白你可以用新方法以相同的方式使用@BindingAdapter?我刚刚开始使用mvvm,所以我对谁应该处理地图更新感到困惑。 – leojg
据我所知,不禁止使用MapView本身(MapFragment本身是什么),但您只需要照顾将生命周期事件传递给MapView – Ivan