2014-11-20 1 views
0

나는 여기에 비슷한 글을 많이 보았지만 아무도 지금까지 나를 도왔다. 나는 자바 스크립트에서 이것을하고있다. 나는 벡터 (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) 및 위도/경도 크게 감사드립니다, 감사!

+0

거리를 어떻게 받고 있습니까? 문제를 어떻게 재현 할 수 있습니까? [Minimal, Complete, Tested and Readable example] (http://stackoverflow.com/help/mcve)를 제공해주십시오. – geocodezip

+0

사람들이 Leap Motion에 익숙하지 않은 경우를 대비해 적은 정보를 제공하려고했습니다. 또한 여러 곳에서 콘솔 메시지를 인쇄하여 내가 얻는 정보가 정확하다고 생각하게합니다. 계산 (즉, 데이터 변환)이 무언가 정확하지 않은 경우를 제외하고는 정확합니다. 하지만 당신이 Leap Motion에 익숙하다면, 내가 얻는 거리는 keyTapGesture.position [0] (X의 경우, [1]의 경우)입니다. 그런 다음 위 거리를 위도와 경도로 변환하려고합니다. – user3727351

답변

1

그래서 첫 번째 단계로 분리하고 디버그하여 작동하는지 확인해야합니다. 즉, 도약 모션 위치 좌표가 화면 픽셀 좌표로 변환되는 방식에 만족하는지 확인하십시오.

일반적으로 2 차원에서 약간 까다로울 수 있습니다. 일반적으로 z 차원을 버리고 선형 눈금 계수를 도입하여 mm에서 px로 변환합니다.

이 예제를 사용해 보셨습니까? https://developer.leapmotion.com/libraries/screenposition-plugin

소스 코드 : 당신의 픽셀 (일반적으로 마우스에서) 화면 위치를 필요로하는 API 좌표에두고 https://github.com/leapmotion/leapjs-plugins/tree/master/main/screen-position

, 당신은 연결할 수 있습니다.

+0

예제를 살펴 보았는데, 실제로 도약 위치 좌표에서 화면 픽셀 좌표로가는 방법에 대해 약간 혼란 스럽습니다. 나는 그것이베이스 스케일을 6으로하고베이스 오프셋을 -100으로 사용하고 있다고 생각한다. 이 번호는 어디서 오는 것입니까? 미안하지만 난 아직 이러고있어. 도움을 주셔서 감사합니다 – user3727351

+0

숫자는 임의적입니다 - 당신의 앱으로 도약을 위해, 사용하기에 좋은 것. –

+0

예를 들어 x 좌표의 공식은'(window.innerWidth/2) + (hand.palmPosition [0] * scale)'입니다. 그것은 도약의 중간을 창 중앙과 정렬시킵니다. –

관련 문제