在android v2 mapview中居中固定标记 [英] Center fixed marker in android v2 mapview
问题描述
我想在拖动地图时在mapview
的中心点设置固定标记.已在android map v1 google mapview
上完成.但是现在不推荐使用了.现在我的问题是,是否可以在android Map V2 google mapview
中使用?(我已经尝试过了,但是地图没有显示)
I want to set fixed marker in the center point of mapview
while dragging map.It has been done at android Map V1 google mapview
. But now it's deprecated.Now my question is, is it possible in android Map V2 google mapview
?(I have tried.but map doesn't show)
推荐答案
我敢打赌,您使用了getMapCenter()
,根据适用于Android v2的Google Maps,它不再可用.但不用担心,只需使用此:
I'm betting you used getMapCenter()
which, as per Google Maps for Android v2, no longer available to use. But no worries, just use this:
GoogleMap.getCameraPosition().target
它将返回一个LatLng
对象,该对象基本上表示地图的中心.然后,通过在GoogleMap
上分配OnCameraChangedListener
,可以在每次发生拖动事件时使用它来将标记重新定位到中心.
It will return a LatLng
object which basically represents the center of the map. You can then use it to reposition the marker to the center every time there's a drag event by assigning an OnCameraChangedListener
to your GoogleMap
.
yourGMapInstance.setOnCameraChangeListener(new OnCameraChangedListener() {
@Override
public void onCameraChange (CameraPosition position) {
// Get the center of the Map.
LatLng centerOfMap = yourGMapInstance.getCameraPosition().target;
// Update your Marker's position to the center of the Map.
yourMarkerInstance.setPosition(centerOfMap);
}
});
在那里.希望对您有所帮助!
There. I hope this helped!
这篇关于在android v2 mapview中居中固定标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!