나는 (SQL과 같은 방식으로) 자동적으로이 작업을 수행 할 수있는 방법을 알고하지 않습니다,하지만 당신은 (코드에 주석 참조) 다음과 같은 무언가를 시도 할 수 :
라이브 예를 here.
/* Declare utility function to convert degrees to radians */
function radians(deg) {
return deg * Math.PI/180;
}
/* Declare utility function to compute distance from (37, -122) */
/* (If these values change dynamically they should */
/* be given as parameters to the function.) */
var cos37 = Math.cos(radians(37));
var sin37 = Math.sin(radians(37));
function distance(lat, long) {
var dist = 3959
* Math.acos(cos37
* Math.cos(radians(lat))
* Math.cos(radians(long)
- radians(-122))
+ sin37
* Math.sin(radians(lat)));
return dist;
}
/* Somehow populate a 2-dimensional array containing all entries. */
/* Each row should look like this: [id, latitude, longtitude] */
var allArr = ...; // [[id1, lattitude1, longtitude1],[id2, lattitude2, longtitude2],...]
/* Populate a new array containing [id, distance] of those entries */
/* whose distance from (37, -122) is less than 12925. */
var newArr = [];
for (var i = 0; i < allArr.length; i++) {
var dist = distance(allArr[i][1]/*latitude*/,
allArr[i][2]/*longtitude*/);
if (dist < 12925) {
newArr.push([allArr[i][0]/*id*/,
dist]);
}
}
은 또한 당신이 어떤 extraterestrial 웹 응용 프로그램을 디자인하지 않는 그래서, 당신은 당신의 사양 :
을 개정 할 수 있습니다, 12,925마일보다 큰 거리로 지구에 두 장소를 찾는 것은 불가능하다 것으로 나타났습니다
'나는 자바 스크립트 배열로 db를 내보냈습니다. '.. 당신은 확실합니다 ... 왜냐하면 javascirpt는 클라이언트 측이고 SQL은 서버에 있습니다 ... – bipen
그래서, 당신은 자바 스크립트 배열로 테이블 데이터를 가지고 있습니다. 다시 말해? 그리고 자바 쿼리를 사용하여 동일한 결과를 얻으려면 자바 스크립트를 사용하고 싶습니까? 아직 아무 것도 시도하지 않았습니까? – Yatrix
@bipen 예, json_encode를 사용했습니다. –