我想用虚线创建一条带有实线的多边形,这是不是可能?
我知道你可以在onDraw
覆盖覆盖的v1
方法时执行此操作,但Overlay
类不再存在,那么我怎么能实现这个呢?
答案 0 :(得分:3)
目前无法实现,但您可以在此处推荐此增强功能:http://code.google.com/p/gmaps-api-issues/issues/detail?id=4633
<强>更新强>
最近,Google在Google Maps Android API v2中为折线和多边形实现了此功能,并将问题4633标记为已修复。
请参阅Shapes Guide中有关笔画模式的信息。请参阅“折线和多边形”教程中的example。
您还可以在此处阅读相应的博文:
https://maps-apis.googleblog.com/2017/02/styling-and-custom-data-for-polylines.html
答案 1 :(得分:1)
v2尚不可能,但是在v3 javascript API上,它已经是,请看这里: https://developers.google.com/maps/documentation/javascript/overlays#PolylineSymbols
但似乎可以在Android应用中使用这个v3 javascript API,请看这里: https://developers.google.com/maps/articles/android_v3
也许,这会对你有帮助
答案 2 :(得分:1)
在地图上距离中心LatLng的半径单位距离处找到LatLng 现在将这些LatLng转换为screenCoordinates
使用用于构造cirle的公式x = R sin(theta),y = R cos(theta)
将圆分为N段,然后在圆周上绘制折线(在地图上绘制),将屏幕坐标转换为LatLngs
更多N的数量看起来像一个圆圈,我根据缩放级别使用N = 120,我使用的是13。
private void addDottedCircle(double radius) {//radius is in kms
clearDottedCircle();
LatLng center,start,end;
Point screenPosCenter,screenPosStart,screenPosEnd;
Projection p = mMap.getProjection();
center = searchCenterMarker.getPosition();
start = new LatLng(center.latitude + radius/110.54,center.longitude);
// radius/110.54 gives the latitudinal delta we should increase so that we have a latitude at radius distance
// 1 degree latitude is approximately 110.54 kms , so the above equation gives you a rough estimate of latitude at a distance of radius distance
screenPosCenter = p.toScreenLocation(center);
screenPosStart = p.toScreenLocation(start);
double R = screenPosCenter.y - screenPosStart.y;
int N = 120;//N is the number of parts we are dividing the circle
double T = 2*Math.PI/N;
double theta = T;
screenPosEnd = new Point();
screenPosEnd.x = (int)(screenPosCenter.x-R*Math.sin(theta));
screenPosEnd.y = (int) (screenPosCenter.y-R*Math.cos(theta));
end = p.fromScreenLocation(screenPosEnd);
for(int i =0;i<N;i++){
theta+=T;
if(i%2 == 0){
//dottedCircle is a hashmap to keep reference to all the polylines added to map
dottedCircle.add(mMap.addPolyline(new PolylineOptions().add(start,end).width(5).color(Color.BLACK)));
screenPosStart.x = (int) (screenPosCenter.x-R*Math.sin(theta));
screenPosStart.y = (int) (screenPosCenter.y-R*Math.cos(theta));
start = p.fromScreenLocation(screenPosStart);
}
else{
screenPosEnd.x = (int)(screenPosCenter.x-R*Math.sin(theta));
screenPosEnd.y = (int) (screenPosCenter.y-R*Math.cos(theta));
end = p.fromScreenLocation(screenPosEnd);
}
}
}
答案 3 :(得分:0)
如果您仍在寻找答案,请查看: