const test =()=>{
const error=()=>{
console.log('에러야~~')
}
const success=(position)=>{
const latitude = position.coords.latitude;
const longitude = position.coords.longitude;
console.log(latitude)
console.log(longitude)
console.log('성공')
}
navigator.geolocation.getCurrentPosition(success, error)
}
이게 걍 단순하게 쓴거고..
latitude와 longitude를 구해준다.
저 getCurrentPosition콜백에 success error함수 두개를 파라미터로 넣으면
success 함수의 파라미터에 알아서 넣어주는 형식이더라.. 좀 특이했음.
암튼 위도경도 구해주더라.
# 아래는 구글링에서 찾은코드
function geoFindMe() {
const status = document.querySelector("#status");
const mapLink = document.querySelector("#map-link");
mapLink.href = "";
mapLink.textContent = "";
function success(position) {
const latitude = position.coords.latitude;
const longitude = position.coords.longitude;
status.textContent = "";
mapLink.textContent = `Latitude: ${latitude} °, Longitude: ${longitude} °`;
}
function error() {
status.textContent = "Unable to retrieve your location";
}
if (!navigator.geolocation) {
status.textContent = "Geolocation is not supported by your browser";
} else {
status.textContent = "Locating…";
navigator.geolocation.getCurrentPosition(success, error);
}
}
에러처리할때 참고하면될듯..
참고로 위도 경도 기반으로 주소지 찾아내는건 구글 api 이용하면서 키 발급받아야하는데
졸려서 여기까지
'project > miniCode' 카테고리의 다른 글
객체 키값 벨류값 순회 반복문 (0) | 2022.10.26 |
---|---|
글자수 용량 알아보기 (0) | 2022.07.30 |
브라우저에서 복사버튼 만들기. (0) | 2022.07.29 |
axios데이터 & 헤더값 포함 (0) | 2022.07.16 |
nodejs // http서버와 axios를 이용한 크롤러 (0) | 2022.06.30 |