나는 여기에 비슷한 글을 많이 보았지만 아무도 지금까지 나를 도왔다. 나는 자바 스크립트에서 이것을하고있다. 나는 벡터 (X, Y, Z)의 형태로 Leap Motion 소프트웨어를 사용하여 화면에서 취한 위치를 변환해야하며 좌표 (위도) 형식의 Google maps 위치로 변환해야합니다. , 경도). 도약 모션 제스처 (화면의 커서로 생각)와 Google지도 API에 표시되는 마커 사이의 거리를 계산하려고합니다. 현재 내 공식은 다음과 같습니다.벡터 (X, Y) 위치를 위도/경도 좌표로 변환하는 방법은 무엇입니까? 자바 스크립트
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) 및 위도/경도 크게 감사드립니다, 감사!
거리를 어떻게 받고 있습니까? 문제를 어떻게 재현 할 수 있습니까? [Minimal, Complete, Tested and Readable example] (http://stackoverflow.com/help/mcve)를 제공해주십시오. – geocodezip
사람들이 Leap Motion에 익숙하지 않은 경우를 대비해 적은 정보를 제공하려고했습니다. 또한 여러 곳에서 콘솔 메시지를 인쇄하여 내가 얻는 정보가 정확하다고 생각하게합니다. 계산 (즉, 데이터 변환)이 무언가 정확하지 않은 경우를 제외하고는 정확합니다. 하지만 당신이 Leap Motion에 익숙하다면, 내가 얻는 거리는 keyTapGesture.position [0] (X의 경우, [1]의 경우)입니다. 그런 다음 위 거리를 위도와 경도로 변환하려고합니다. – user3727351