Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Нет возможности устанавливать остановки на маршруте. multiRoute #266

Open
alen-s opened this issue Oct 31, 2023 · 1 comment

Comments

@alen-s
Copy link
Contributor

alen-s commented Oct 31, 2023

При просмотре https://yandex.com/dev/maps/jsbox/2.1/multiroute_view_options вы можете заметить, что на маршруте розовым маркером отмечена «Кремлёвская набережная».
Есть ли у нас такой функционал? И если нет, когда вы планируете над этим работать?

CC: @ownikss

@alen-s
Copy link
Contributor Author

alen-s commented Nov 16, 2023

By the way, you can use this code to determine the nearest point on the route by given points coords.
2023-11-16_19-44

const findNearestPointOnRoute = (
    routePoints: string | any[],
    givenPoints: any[],
  ) => {
    return givenPoints.map((givenPoint: any) => {
      let minDistance = Number.MAX_VALUE;
      let nearestPoint = null;

      // Calculate distance for each point on the route
      for (let i = 0; i < routePoints.length; i++) {
        const routePoint = routePoints[i];
        const distance = calculateHaversineDistance(givenPoint, routePoint);

        // Update nearest point if the current point is closer
        if (distance < minDistance) {
          minDistance = distance;
          nearestPoint = routePoint;
        }
      }

      return nearestPoint;
    });
  };
  
  // Function to calculate Haversine distance between two points
  const calculateHaversineDistance = (
    point1: {lat: number; lon: number},
    point2: {lat: number; lon: number},
  ) => {
    const R = 6371; // Radius of the Earth in kilometers
    const dLat = toRadians(point2.lat - point1.lat);
    const dLon = toRadians(point2.lon - point1.lon);

    const a =
      Math.sin(dLat / 2) * Math.sin(dLat / 2) +
      Math.cos(toRadians(point1.lat)) *
        Math.cos(toRadians(point2.lat)) *
        Math.sin(dLon / 2) *
        Math.sin(dLon / 2);

    const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));

    // Distance in kilometers
    return R * c;
  };

  // Helper function to convert degrees to radians
  const toRadians = (degrees: number) => {
    return degrees * (Math.PI / 180);
  };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant