【发布时间】:2016-04-27 15:37:04
【问题描述】:
只是想知道如何将纬度和经度绑定到com.google.android.gms.maps.MapView。感觉它没有为此公开任何布局属性。
【问题讨论】:
只是想知道如何将纬度和经度绑定到com.google.android.gms.maps.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 是使用地图的正确方式吗?我的意思是,每个文档都告诉您使用片段,我想知道这是否是一种已弃用的方式。