服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - Android - Android实现百度地图两点画弧线

Android实现百度地图两点画弧线

2022-09-14 16:26miskss Android

这篇文章主要为大家详细介绍了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;
 }
}

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

原文链接:https://blog.csdn.net/wanping321/article/details/85990561

延伸 · 阅读

精彩推荐