![](/img/trans.png)
[英]Using react-native-maps to Change pinColor of MapView.Marker
[英]How to find the degree of rotation for marker on map while using react-native-maps with google maps api?
我正在尝试使用 react-native 制作一个类似 uber 的应用程序。我正在使用 react-native-maps。 我已经成功地使用谷歌地图的方向 api 绘制了方向,并且我已经能够成功地在路径上移动我的汽车标记,但问题是汽车的方向。 我想随着道路方向的变化而改变汽车的方向。 很长一段时间以来,我一直在努力寻找一种方法,但一无所获。 如果有人可以提供帮助,将不胜感激。
您可以使用以下 function 找到两个坐标之间的旋转度数
const calculateHeading = (cord1, cord2) => {
if (cord2) {
const {latitude: lat1, longitude: lng1} = cord1;
const {latitude: lat2, longitude: lng2} = cord2;
const y = Math.sin(lng2 - lng1) * Math.cos(lat2);
const x =
Math.cos(lat1) * Math.sin(lat2) -
Math.sin(lat1) * Math.cos(lat2) * Math.cos(lng2 - lng1);
const θ = Math.atan2(y, x);
const brng = ((θ * 180) / Math.PI + 360) % 360;
return brng;
}
return 0;
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.