메뉴 건너뛰기

프로그램언어

?

단축키

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. 13자리 timestamp 생성하기

    Date2020.09.28 Views649
    Read More
  2. cUrl를 이용한 json 데이타 주고 받기

    Date2020.09.28 Views1253
    Read More
  3. Javascript 두 좌표 사이의 거리 구하기, 두 좌표의 중앙 좌표 구하기

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

    Date2020.09.22 Views490
    Read More
  5. 사업자등록번호 유효성 체크

    Date2020.08.24 Views470
    Read More
  6. 멀티 파일다운로드 꽁수로 구현하기

    Date2020.06.19 Views437
    Read More
  7. 파일 다운로드 함수(멀티 이어받기/속도제한)

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

    Date2020.06.19 Views616
    Read More
  9. 사진이 회전되서 올라갈 경우

    Date2020.05.25 Views767
    Read More
  10. PHP 버전이 낮아 imagerotate() 함수가 없을때 대신 사용하는 함수

    Date2019.12.31 Views644
    Read More
  11. PHP 외부 XML 파싱 하기

    Date2019.06.24 Views1942
    Read More
  12. 주간단위 시작일에서 종료일을 셀렉트박스로 만들기.

    Date2019.04.29 Views1331
    Read More
  13. utf-8 문자열을 주어진 바이트로 자르기

    Date2019.04.29 Views1356
    Read More
  14. PHP $_SERVER 함수

    Date2019.02.25 Views1558
    Read More
  15. PHP에서 UTF와 EUC-KR 변환

    Date2019.02.19 Views1553
    Read More
  16. PHP 가변변수 $$

    Date2019.02.19 Views1449
    Read More
  17. PHP http 를 https 로 전환(redirect), http->https

    Date2019.02.19 Views2182
    Read More
  18. input 자동완성기능 끄기

    Date2019.02.19 Views1217
    Read More
  19. dddotag - 허용하지 않는 태그 걸러내기

    Date2019.01.16 Views1850
    Read More
  20. 애니메이션 gif 와 일반 gif 구분 하기

    Date2019.01.16 Views1313
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 17 Next
/ 17

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved