메뉴 건너뛰기

프로그램언어

?

단축키

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. JSON and JavaScript usage

    Date2014.03.26 Views19066
    Read More
  2. jquery 이용 아이디 중복체크 실시간

    Date2014.04.12 Views20351
    Read More
  3. jQuery 개발자를 위한 메모 - 플러그 인

    Date2014.03.26 Views19258
    Read More
  4. jQuery 개발자를 위한 메모 - 레퍼런스

    Date2014.03.26 Views19524
    Read More
  5. JAVASCRIPT 차트, 그래프 모음 (php chart, graph )

    Date2021.03.26 Views1636
    Read More
  6. Javascript 두 좌표 사이의 거리 구하기, 두 좌표의 중앙 좌표 구하기

    Date2020.09.23 Views544
    Read More
  7. is_array — 변수가 배열인지 확인

    Date2016.12.23 Views18051
    Read More
  8. input 자동완성기능 끄기

    Date2019.02.19 Views1225
    Read More
  9. ini_get - php.ini에 지정되어 있는 지시어의 값을 읽어온다

    Date2016.12.23 Views19521
    Read More
  10. include 와 namespace

    Date2019.01.08 Views1105
    Read More
  11. implode — 문자열로 배열 원소를 결합

    Date2016.12.23 Views19958
    Read More
  12. iframe 사용시 iframe의 높이가 내용의 높이만큼 자동으로 조절

    Date2014.04.12 Views21865
    Read More
  13. http://홈주소/?mode=xxx 하는방법

    Date2017.03.07 Views17657
    Read More
  14. HTTP 인증하기, 로그인창 띄우기

    Date2021.03.26 Views215
    Read More
  15. HTTP Protocol의 data method - GET / POST

    Date2016.04.22 Views20642
    Read More
  16. htmlentities <-> html_entity_decode (엔티티

    Date2014.04.12 Views30602
    Read More
  17. HEREDOC <<< ( PHP에서 echo로 HTML쉽게 표시하기 )

    Date2021.03.26 Views380
    Read More
  18. headers_sent 헤더 전송 여부를 확인

    Date2016.12.23 Views19418
    Read More
  19. glob 현재 디렉토리에서 pattern에 일치하는 경로 이름을 배열로 반환

    Date2016.12.23 Views19641
    Read More
  20. GD를 이용한 스팸성 게시물 차단을 위한 보안 단어 입력 예제

    Date2014.02.27 Views26951
    Read More
Board Pagination Prev 1 ... 8 9 10 11 12 13 14 15 16 17 Next
/ 17

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved