Geolocation API
- 현재 위치 정보를 제공하는 WebAPI.
- HTTPS에서 지원.
navigator.geolocation 객체의 getCurrentPosition 메서드로 현재 위치를 얻을 수 있음.
navigator.geolocation.getCurrentPosition(successCallback, [errorCallback, options])
Kakao Map API
import React, { useEffect, useRef } from 'react';
declare global {
interface Window {
kakao: any;
}
}
function KakaoMap({
mapHeight,
mapWidth,
latLong,
levelNum,
draggableType,
trafficInfo,
}: {
mapHeight: string;
mapWidth: string;
latLong: { latitude: number; longitude: number };
levelNum: number;
draggableType: boolean;
trafficInfo: boolean;
}) {
const mapRef = useRef(null);
useEffect(() => {
const container = mapRef.current;
const options = {
center: new window.kakao.maps.LatLng(latLong.latitude, latLong.longitude),
draggable: draggableType,
disableDoubleClick: true,
level: levelNum,
};
const map = new window.kakao.maps.Map(container, options);
trafficInfo && map.addOverlayMapTypeId(window.kakao.maps.MapTypeId.TRAFFIC);
const imageSrc = '/logo/breadkun-marker.png';
const imageSize = new window.kakao.maps.Size(37, 41);
const imageOption = { offset: new window.kakao.maps.Point(15, 35) };
const markerImage = new window.kakao.maps.MarkerImage(imageSrc, imageSize, imageOption);
const markerPosition = new window.kakao.maps.LatLng(latLong.latitude, latLong.longitude);
const marker = new window.kakao.maps.Marker({
position: markerPosition,
image: markerImage,
});
marker.setMap(map);
}, [levelNum, draggableType, trafficInfo, latLong]);
return (
<div>
<div ref={mapRef} style={{ height: mapHeight, width: mapWidth, borderRadius: '10.26vw', isolation: 'isolate' }} />
</div>
);
}
KakaoMap.defaultProps = {
levelNum: 5,
draggableType: false,
trafficInfo: false,
};
export default KakaoMap;