Android的 - 谷歌地图做出标记粘 [英] Android - Google Map make marker sticky
本文介绍了Android的 - 谷歌地图做出标记粘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有我的MapFragment以下标记code。我想这个标记坚持下去的地位。意味着我要在地图中心位置标记,当我移动/拖动地图标记,然后应该不会被移动。如何做到这一点与下面的标记?
I have following marker code on my MapFragment. I want this marker stick to it's position. Means I want marker at center position in map and when I move/drag map then marker shouldn't get moved. How to do that with following marker?
PlaceMarker = PlaceMap.addMarker(
new MarkerOptions()
.position(new LatLng(0, 0))
.draggable(true)
.title("Drag Me"));
PlaceMarker.showInfoWindow();
感谢
推荐答案
您可以在用户平移地图上的中心添加一个侦听器,并设置标志。
You can add a listener when the user pans the map and set the marker on the center.
mMap.setOnCameraChangeListener(new OnCameraChangeListener() {
public void onCameraChange(CameraPosition cameraPosition) {
mMap.clear();
mMap.addMarker(new MarkerOptions().position(cameraPosition.target));
}
});
这样做的另一种方法是通过覆盖一个标记图标(不是真实标记;在XML布局定义)。与得到的位置时,用户设置,作为一个位置
Another way of doing this is by overlaying a marker icon (Not a real marker; defined in your XML layout) and get the location when the user sets that as a location.
这篇关于Android的 - 谷歌地图做出标记粘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文