如何在使用Google Maps API的反应型映射时在地图上找到标记的旋转程度?

发布于 01-20 08:57 字数 183 浏览 3 评论 0原文

我正在尝试使用react-native制作一个像超级应用程序一样的应用程序。我正在使用反应本机地图。我已经使用谷歌地图的方向 api 成功地绘制了方向,并且我已经能够成功地在路径上移动我的汽车标记,但问题是汽车的方向。我想随着道路方向的变化而改变汽车的方向。我长期以来一直在寻找一种方法来做到这一点,但我一无所获。如果有人可以提供帮助,我们将不胜感激。

I am trying to make an uber like app using react-native. I am using react-native-maps. I have successfully mapped the directions using directions api of google maps, and I have been able to move my car marker on the path successfully, but the problem is the direction of the car. I want to change the direction of the car as the direction of the road changes. I have been trying to find a way to do it for a long time, but I have found nothing. If anyone can help, that will be much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱要勇敢去追2025-01-27 08:57:39

您可以使用以下功能找到两个坐标之间的旋转程度

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;
  };

You can find the the degree of rotation between two coordinates by using the following 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;
  };
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文