在Android中绘制带有预览的圆形地理围栏
首先,我的问题与其他关于Android中gmap中地理围栏的问题有些不同 当用户开始将一个圆定义为地理围栏区域时,我希望在屏幕中央显示一个固定的圆。在此阶段,用户应该能够移动地图和地图的缩放级别。“移动”操作或“放大/缩小”操作都不能更改相对于屏幕的圆圈大小 当用户按下保存按钮时,我想将该圆作为CircleOption对象固定到地图上。然后,我将能够得到lon/lat和圆周运动物体的半径,单位为米 我目前正在处理RelativeLayout问题。我画了一个固定的带有RelativeLayout的圆,正如我所期望的,但是我不能得到那个相对论Layout圆的当前半径。你可以看到我的亲戚你现在的样子: 我不确定这样做的正确方法。我的搜索重定向到使用RelativeLayout,然后使用CircleOption。你有什么建议在Android中绘制带有预览的圆形地理围栏,android,google-maps,android-layout,geofencing,android-geofence,Android,Google Maps,Android Layout,Geofencing,Android Geofence,首先,我的问题与其他关于Android中gmap中地理围栏的问题有些不同 当用户开始将一个圆定义为地理围栏区域时,我希望在屏幕中央显示一个固定的圆。在此阶段,用户应该能够移动地图和地图的缩放级别。“移动”操作或“放大/缩小”操作都不能更改相对于屏幕的圆圈大小 当用户按下保存按钮时,我想将该圆作为CircleOption对象固定到地图上。然后,我将能够得到lon/lat和圆周运动物体的半径,单位为米 我目前正在处理RelativeLayout问题。我画了一个固定的带有RelativeLayout的
提前谢谢 一种方法是在XML的相对布局中定义一个圆。这将由用户定义,而不是地图可以在它下面移动。获取圆的中心作为整个地图片段布局的中心坐标,并且您已经定义了圆的半径,您知道圆下扫掠的区域是什么 前提是用户无法缩放地图 希望这会有帮助
https://developers.google.com/android/reference/com/google/android/gms/maps/model/Circle
https://developers.google.com/android/reference/com/google/android/gms/maps/model/Circle
CircleOptions circleOptions = new CircleOptions()
.center( new LatLng(fence.getLatitude(), fence.getLongitude()) )
.radius( fence.getRadius() )
.fillColor(0x40ff0000) <Your Color code>
.strokeColor(Color.TRANSPARENT)
.strokeWidth(2);
CircleOptions CircleOptions=新的CircleOptions()
.center(新板条(fence.getLatitude()、fence.getLongitude())
.radius(fence.getRadius())
.fillColor(0x40ff0000)
.strokeColor(颜色.透明)
.冲程宽度(2);
已编辑。
如果我正确理解你的问题,问题是如何将相对坐标转换为土工栅栏的半径米?
试试这个
更好的方法是使用
android.graphics.Point centerPoint = new android.graphics.Point(100, 100);//center of Circle on the screen
LatLng centerLatLang = mMap.getProjection().fromScreenLocation(centerPoint);
int radius = 50;//Radius of the circle on the screen
android.graphics.Point radiusPoint = new android.graphics.Point(centerPoint.x+radius, centerPoint.y);
LatLng radiusLatLang = mMap.getProjection().fromScreenLocation(radiusPoint);
float[] results = new float[1];
Location.distanceBetween(centerLatLang.latitude, centerLatLang.longitude, radiusLatLang.latitude, radiusLatLang.longitude, results);
float radiusInMeters = results[0];
如果要将fron latLang转换为点,请使用
mMap.getProjection().toScreenLocation(latLng)
圆圈
是通向IMHO的道路。它具有圆所需的一切:半径、中心、填充颜色等。只需使用该圆作为标记,就比使用自定义相对值IMGO更好了。对于添加地理围栏-->mGoogleMap.addCircle(circleOptions);用于在地图中添加。