Я видел много подобных сообщений здесь, на SO, но пока никто мне не помог. Я делаю это в Javascript. Мне нужно преобразовать положение, взятое на экране, с помощью программного обеспечения Leap Motion в виде вектора (X, Y, Z) и преобразовать его в положение на картах Google, которое находится в виде координаты (широта , долгота). Я пытаюсь рассчитать расстояние между жестом движения прыжка (представьте, что это курсор на экране) и маркерами, отображаемыми на API карт Google. В настоящее время моя формула:
function convertToLatLng(x, y){
// retrieve the lat lng for the far extremities of the (visible) map
var latLngBounds = map.getBounds();
var neBound = latLngBounds.getNorthEast();
var swBound = latLngBounds.getSouthWest();
// convert the bounds in pixels
var neBoundInPx = map.getProjection().fromLatLngToPoint(neBound);
var swBoundInPx = map.getProjection().fromLatLngToPoint(swBound);
// compute the percent of x and y coordinates related to the div containing the map; in my case the screen
var procX = x/window.innerWidth;
var procY = y/window.innerHeight;
// compute new coordinates in pixels for lat and lng;
// for lng : subtract from the right edge of the container the left edge,
// multiply it by the percentage where the x coordinate was on the screen
// related to the container in which the map is placed and add back the left boundary
// you should now have the Lng coordinate in pixels
// do the same for lat
var newLngInPx = (neBoundInPx.x - swBoundInPx.x) * procX + swBoundInPx.x;
var newLatInPx = (swBoundInPx.y - neBoundInPx.y) * procY + neBoundInPx.y;
// convert from google point in lat lng and have fun :)
var newLatLng = map.getProjection().fromPointToLatLng(new google.maps.Point(newLngInPx, newLatInPx));
return newLatLng;
}
который я нашел из другого поста SO, но расстояния, которые я получаю, всегда неверны. Например, если у меня есть два маркера на карте, независимо от того, куда я поместил курсор прыжкового движения, моя функция всегда будет говорить мне, что ближайший из них — это маркер B.
Будем очень благодарны за любую помощь в преобразовании между вектором (X, Y) и широтой/долготой, спасибо!