温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2021-04-16 11:11:31 来源:亿速云 阅读:241 作者:小新 栏目:移动开发

这篇文章给大家分享的是有关Android怎么实现百度地图两点画弧线的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

具体内容如下

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,h3;
 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));
 h3 = h / 2;
 double lng3 = h3 * Math.cos(t2) + lng1;
 double lat3 = h3 * 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怎么实现百度地图两点画弧线”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI