[英]Android:Google map v2 draw dragable circle
I need to draw circle of some radius on some given location that can be dragged to some other point on map I can well draw circle like this 我需要在某个给定的位置绘制一些半径的圆,可以拖到地图上的其他点我可以像这样绘制圆圈
mMap.addCircle(new CircleOptions().center(circleLocation).radius(10).strokeColor(Color.RED).fillColor(Color.RED));
Now I need to drag this circle on map in such a way that when I click on this circle map gets locked and on moving my finger this circle should move on circle and not map itself 现在我需要在地图上拖动这个圆圈,这样当我点击这个圆形地图时会被锁定并且在移动我的手指时这个圆圈应该在圆圈上移动而不是自己映射
Thanks in advance!!! 提前致谢!!!
I don't know how to do with shapes but one alternative is to use a marker. 我不知道如何处理形状,但另一种方法是使用标记。 It doesn't have the exact result as the marker is drawn flush to the screen view rather than flush to the map but it does have built in drag support.
它没有确切的结果,因为标记被刷新到屏幕视图,而不是刷新到地图,但它确实内置了拖动支持。 You would need to create a circle image.
您需要创建一个圆形图像。
map.addMarker(new MarkerOptions()
.position(MELBOURNE)
.title("Melbourne")
.draggable(true)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.circle)));
View
above the SupportMapFragment
SupportMapFragment
上方添加一个View
OnTouchListener
to this View
OnTouchListener
添加到此View
Projection
to convert x,y to LatLng
and Location.distanceBeetween
Projection
的组合将x,y转换为LatLng
和Location.distanceBeetween
false
to give map chance to handle event false
以给予映射机会处理事件 true
and save relevant variables true
并保存相关变量 Projection
to calculate new center based on initial and new x,y Projection
根据初始和新x,y计算新中心 Here is the code to draw circle above map, 这是在地图上绘制圆圈的代码,
CircleOptions circleOptions = new CircleOptions()
.center(new LatLng(37.4, -122.1))
.radius(1000)); // In meters
// Get back the mutable Circle
Circle circle = myMap.addCircle(circleOptions);
And GoogleMap doesn't have a touch listener, so you'll have to override onTouchEvent for the parent view of your MapFragment to drag your circle around. 并且GoogleMap没有触控侦听器,因此您必须覆盖onTouchEvent以使MapFragment的父视图拖动您的圆圈。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.