Android实现百度地图两点画弧线
作者:miskss 发布时间:2022-08-17 14:52:03
标签: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文件中计算第三个点的方式
* <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
0
投稿
猜你喜欢
- 一、闭包的定义。有很多不同的人都对闭包过进行了定义,这里收集了一些。# 是引用了自由变量的函数。这个函数通常被定义在另一个外部函数中,并且引
- 结论:HashMap对象的key、value值均可为null。HahTable对象的key、value值均不可为null。且两者的的key值
- 本人所使用的开发环境是VS2008,开发的系统所在移动终端版本为windows mobile 5.0。由于需要进行身份的验证,需要获取移动终
- 出错信息:Unknown error (0xffffffff)at System.Diagnostics.Process.StartWith
- 1. 插入排序步骤:1.从第一个元素开始,该元素可以认为已经被排序2.取下一个元素tem,从已排序的元素序列从后往前扫描3.如果该元素大于t
- 一、获取程序集版本 程序代码 label版本.Text = System.Reflection.Assembly.GetExecutingA
- 一、项目简述环境配置:Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,
- JAVA IDEA 打开assert 设置概念(此处为借鉴前辈们的讲解)断言(Assertion)是Java中一条语句,包含一个布尔表达式,
- 页面提交请求参数有两种,一种是form格式提交,一种json格式提交通常情况下我们使用的都是form格式提交的数据,数据格式:k=v&
- 这篇文章主要介绍了基于Jasypt对SpringBoot配置文件加密,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习
- 就不多叙述了,直接上代码import android.content.Context;import android.graphics.Can
- 题目给定count=0;让5个线程并发累加到1000;思路创建一个类MyRunnable,实现Runnable(继承Thread类也可)定义
- 数字9 出现的次数编写程序数一下 1到 100 的所有整数中出现多少个数字9源码public static int Getnum
- 本文实例讲述了Android读取assets目录下的所有图片并显示的方法。分享给大家供大家参考。具体方法分析如下:在assets文件夹里面的
- 最近在刷力扣上的题目,刷到了65不同路径,当初上大学的时候,曾在hihocoder上刷到过这道题目,但是现在已经几乎全忘光了,大概的知识点是
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&
- 问题:在web里面用iframe连接一个html文件 - html文件里面是超链接 -&nb
- 一、文件的编码package com.study.io;/*** 测试文件编码*/public class EncodeDemo {/***
- 本文实例为大家分享了java实现砸金蛋抽奖的具体代码,供大家参考,具体内容如下代码如下需求:用户每一次砸金蛋,抽中一等奖的概率为2% 二等奖
- 今天看见一个Android 扑克卡片翻转效果的帖子,于是手痒想学一学,由于接触过的Animation动画等比较少,所以感觉很新奇。首先,说一