메뉴 건너뛰기

프로그램언어

?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

 

 

 

- 두 좌표의 중심점을 구하는 함수

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function makeLengthInfo(data){
    var iwContent = '';
    var distanceArray = [];
    data.reduce(function(a,b){
        var d = [];
        var position1 = new daum.maps.LatLng(Number(a.split('/')[0]),Number(a.split('/')[1]));
        var position2 = new daum.maps.LatLng(Number(b.split('/')[0]),Number(b.split('/')[1]));
        d.push(position1, position2);
        var x = (Number(a.split('/')[0])+Number(b.split('/')[0]))/2;
        var y = (Number(a.split('/')[1])+Number(b.split('/')[1]))/2;
        var positions = new daum.maps.LatLng(x,y);
        var infoWinArray = new daum.maps.InfoWindow({
            position: positions,
            zIndex:1,
             content:(getDistanceFromLatLonInKm(d)/1000)+"Km"
        }).setMap(map);
        return b;
    });
}
cs

 

여기서 data의 포멧은 x+"/"+y 데이터가 있는 배열입니다.

두 좌표 사이의 중심 값은 (x1+x2)/2, (y1+y2)/2 로 구하는 것을 보실 수 있습니다.

사용된 reduce 함수에 대해서는 아래의 Link를 참고하세요.

 

Link : javascript reduce 함수에 대해 알아보자 자바스크립트 reduce 함수, reduceRight 함수

 

 

 

 

 

- 두 좌표 사이의 거리를 구하는 함수

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function getDistanceFromLatLonInKm(array) {
    var lat1 = array[0].getLat();
    var lng1 = array[0].getLng();
    var lat2 = array[1].getLat();
    var lng2 = array[1].getLng();
    
    function deg2rad(deg) {
        return deg * (Math.PI/180)
    }
    var r = 6371//지구의 반지름(km)
    var dLat = deg2rad(lat2-lat1);
    var dLon = deg2rad(lng2-lng1);
    var a = Math.sin(dLat/2* Math.sin(dLat/2+ Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.sin(dLon/2* Math.sin(dLon/2);
    var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
    var d = r * c; // Distance in km
    return Math.round(d*1000);
}
cs

 

여기서 매개변수로 받는 배열은 makeLengthInfo 함수를 보시면,

 

1
2
var position1 = new daum.maps.LatLng(Number(a.split('/')[0]),Number(a.split('/')[1]));
var position2 = new daum.maps.LatLng(Number(b.split('/')[0]),Number(b.split('/')[1]));
cs

 

다음지도의 포지션 값인 것을 확인하실 수 있습니다.



출처: https://aljjabaegi.tistory.com/431 [알짜배기 프로그래머]


  1. 경로 제외한 파일 이름만 선택하는 방법, Basename()

    Date2020.11.23 Views430
    Read More
  2. DAUM 지도 API 좌표→주소(주소->좌표) 변환

    Date2020.10.05 Views431
    Read More
  3. 주차 , 요일, 해당주의 시작일, 해당주의 종료일 date()

    Date2021.07.08 Views434
    Read More
  4. 멀티 파일다운로드 꽁수로 구현하기

    Date2020.06.19 Views439
    Read More
  5. 배열 더하기 (+ 를 이용한 배열 합치기 )

    Date2021.03.26 Views451
    Read More
  6. 사업자등록번호 유효성 체크

    Date2020.08.24 Views475
    Read More
  7. 네이버 지도 API를 이용한 주소를 좌표로 변환하기 (PHP)

    Date2020.09.22 Views495
    Read More
  8. CodeIgniter - DB오류체크, 디버깅 여부 설정

    Date2021.03.29 Views496
    Read More
  9. Javascript 두 좌표 사이의 거리 구하기, 두 좌표의 중앙 좌표 구하기

    Date2020.09.23 Views535
    Read More
  10. csv파일 다루기. fputcsv(), fgetcsv()

    Date2021.03.26 Views558
    Read More
  11. substr(), mb_substr(), iconv_substr()

    Date2021.03.26 Views564
    Read More
  12. 알파벳 순서대로 출력하기 ord(), chr()

    Date2021.03.26 Views584
    Read More
  13. 서브도메인 세션 공유

    Date2021.03.26 Views585
    Read More
  14. 파일 다운로드 함수(멀티 이어받기/속도제한)

    Date2020.06.19 Views618
    Read More
  15. 다중 파일을 zip으로 묶어받기

    Date2020.06.19 Views621
    Read More
  16. while, for, foreach 속도 비교

    Date2021.03.26 Views623
    Read More
  17. PHP 버전이 낮아 imagerotate() 함수가 없을때 대신 사용하는 함수

    Date2019.12.31 Views644
    Read More
  18. 13자리 timestamp 생성하기

    Date2020.09.28 Views652
    Read More
  19. 파일을 변수에 담기(ob_start를 이용한 방법)

    Date2021.03.26 Views679
    Read More
  20. PEAR DB 관련 함수들

    Date2021.03.26 Views690
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 17 Next
/ 17

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved