android百度地图画线,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文件中计算第三个点的方式

* http://lbsyun.baidu.com/jsdemo.htm#c1_13

* view-source:http://api.map.baidu.com/library/CurveLine/1.5/src/CurveLine.min.js

* @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;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值