【发布时间】:2016-08-13 08:11:41
【问题描述】:
我正在使用 GoogleMap 片段来使用标记显示一些位置数据。我想要做的是,在地图上画一个以特定距离为半径的圆,这样圆将大致覆盖地图上的某个区域。我不知道从哪里开始,我已经有一张显示位置数据的地图,从位置数据我可以弄清楚这些点与中心位置的距离。
任何帮助都会很棒。
【问题讨论】:
标签: java android google-maps-api-3
我正在使用 GoogleMap 片段来使用标记显示一些位置数据。我想要做的是,在地图上画一个以特定距离为半径的圆,这样圆将大致覆盖地图上的某个区域。我不知道从哪里开始,我已经有一张显示位置数据的地图,从位置数据我可以弄清楚这些点与中心位置的距离。
任何帮助都会很棒。
【问题讨论】:
标签: java android google-maps-api-3
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);
详情请查看:https://developers.google.com/maps/documentation/android-api/shapes
【讨论】:
在调用时需要将
LatLng传递为paramater的地方使用此函数。
private void drawCircle(LatLng point){
CircleOptions circleOptions = new CircleOptions();
// Specifying the center of the circle
circleOptions.center(point);
// Radius of the circle
circleOptions.radius(20);
// Border color of the circle
circleOptions.strokeColor(Color.BLACK);
// Fill color of the circle
circleOptions.fillColor(0x30ff0000);
// Border width of the circle
circleOptions.strokeWidth(2);
// Adding the circle to the GoogleMap
googleMap.addCircle(circleOptions);
}
【讨论】:
使用GoogleMap Circle API。您只需要传递所需的输入就可以了。按照示例中的链接。例如来自 docs ,一个简单的代码结构将如下所示
Circle circle = map.addCircle(new CircleOptions()
.center(new LatLng(-33.87365, 151.20689)) // center point of map
.radius(10000) // radius of circle to cover on map
.strokeColor(Color.RED) //color of circle boundary
.fillColor(Color.BLUE)); //color of circle to fill ,
// make sure choose the light color close to transparent
【讨论】: