[英]Android - Google Map make marker sticky
I have following marker code on my MapFragment. 我的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();
Thanks 谢谢
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));
}
});
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. 另一种方法是覆盖标记图标(不是真正的标记;在XML布局中定义),并在用户将其设置为位置时获取位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.