我是靠谱客的博主 舒心蜻蜓,这篇文章主要介绍Android实现百度地图两点画弧线,现在分享给大家,希望可以做个参考。

本文实例为大家分享了Android实现百度地图两点画弧线的具体代码,供大家参考,具体内容如下

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import android.support.annotation.NonNull; import com.baidu.mapapi.map.ArcOptions; import com.baidu.mapapi.map.OverlayOptions; import com.baidu.mapapi.model.LatLng; /** * * http://lbsyun.baidu.com/index.php?title=androidsdk/guide/render-map/ploygon * 通过两点来绘制弧线 * @author peter 2018-12-24 15:09 */ public class ArcOverlay { private LatLng start; private LatLng end; /** * {@link com.baidu.mapapi.map.ArcOptions#color(int)} */ private int color;//弧线的颜色 private int arcWidth = 4;//弧线宽度 public ArcOverlay(@NonNull LatLng start, @NonNull LatLng end, int color) { this.start = start; this.end = end; this.color = color; } /** * 获取一个弧线Overlay * @param start 起点 * @param end 终点 * @param color 颜色 * @param arcWidth 弧线宽度 */ public ArcOverlay(@NonNull LatLng start, @NonNull LatLng end, int color, int arcWidth) { this.start = start; this.end = end; this.color = color; this.arcWidth = arcWidth; } public OverlayOptions toBmapOverlayOptions() { return new ArcOptions() .color(color) .width(arcWidth) .points(start, getMidPoint(), end); } /** * 参考前端百度提供的画弧线js文件中计算第三个点的方式 * <a>http://lbsyun.baidu.com/jsdemo.htm#c1_13</a> * <a>view-source:http://api.map.baidu.com/library/CurveLine/1.5/src/CurveLine.min.js<a/> * @return 中间点的经纬度 */ private LatLng getMidPoint() { double t, t2, h,h2; double lng1 = start.longitude; double lng2 = end.longitude; double lat1 = start.latitude; double lat2 = end.latitude; if (lng2 > lng1) { if ((lng2 - lng1) > 180) { if (lng1 < 0) { lng1 = (180 + 180 + lng1); } } } if (lng1 > lng2) { if ((lng1 - lng2) > 180) { if (lng2 < 0) { lng2 = (180 + 180 + lng2); } } } if (lat2 == lat1) { t = 0; h = lng1 - lng2; } else { if (lng2 == lng1) { t = Math.PI / 2; h = lat1 - lat2; } else { t = Math.atan((lat2 - lat1) / (lng2 - lng1)); h = (lat2 - lat1) / Math.sin(t); } } t2 = (t + (Math.PI / 5)); h2 = h / 2; double lng3 = h2 * Math.cos(t2) + lng1; double lat3 = h2 * Math.sin(t2) + lat1; return new LatLng(lat3,lng3); } public LatLng getStart() { return start; } public void setStart(LatLng start) { this.start = start; } public LatLng getEnd() { return end; } public void setEnd(LatLng end) { this.end = end; } public int getColor() { return color; } public void setColor(int color) { this.color = color; } public int getArcWidth() { return arcWidth; } public void setArcWidth(int arcWidth) { this.arcWidth = arcWidth; } }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持靠谱客。

最后

以上就是舒心蜻蜓最近收集整理的关于Android实现百度地图两点画弧线的全部内容,更多相关Android实现百度地图两点画弧线内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(107)

评论列表共有 0 条评论

立即
投稿
返回
顶部