map.html 3.28 KB
<!DOCTYPE html>
<html>
    <head>
        <!-- Required meta tags -->
        <meta charset="utf-8">
        <meta name = " description" content ="Open Map and find karaoke">
        <meta name = "author" content = "Hyun Soo Yoo">
        <title>Coin_Karaoke_Map</title>

        <style>
            div{
                height: 100vh;
                background-image: url('C:/Users/user/Documents/coinkaraoke/css/Sing.jpg');
                background-repeat : no-repeat;
                background-size : cover;
            }
        </style>

        <!-- <link rel="stylesheet" href="css/map.css"> -->
        <!-- link x -->
    </head>

    <body>
        <H2 id = "title_message">
            <center>코인 노래방 검색창</center>
        </H2>

        <div id="map" style="width:95%;height:600px;"></div>
        
        <script type="text/javascript" src="//dapi.kakao.com/v2/maps/sdk.js?appkey=8bdb655edc6934f343aaf0c8655559ca">
        </script>

    <script>
        var mapContainer = document.getElementById('map'); // div to display map 
        var mapOption = { 
                center: new kakao.maps.LatLng(33.450701, 126.570667), // coordinates of the center of the map
                level: 3 // Magnification level of the map
            };
        // Create a map with a div to display the map and map options
        var map = new kakao.maps.Map(mapContainer, mapOption); 
            
        if (navigator.geolocation) {

            // Get the connection location using GeoLocation
            navigator.geolocation.getCurrentPosition(function(position) {
                
                var lat = position.coords.latitude, // latitude
                    lon = position.coords.longitude; // longitude
                
                // Creates the location where the marker will be displayed with the coordinates obtained from geolocation
                var locPosition = new kakao.maps.LatLng(lat, lon) 
                    message = '<div style="padding:1px;">여기에 계신가요?!</div>';

                // display a marker
                displayMarker(locPosition,message);

            });
            
        } 
        else { // When HTML5 GeoLocation is not available, set the marker display location and infowindow content
            
            var locPosition = new kakao.maps.LatLng(33.450701, 126.570667),    
                message = 'geolocation을 사용할수 없어요..'

            displayMarker(locPosition,message);
        }

        //function to display a marker on the map
        function displayMarker(locPosition, message) {

            // create a marker
            var marker = new kakao.maps.Marker({  
                map: map, 
                position: locPosition
            }); 

            var iwContent = message, //Contents to display in info window 

            iwRemoveable = true;
            
            // make info window
            var infowindow = new kakao.maps.InfoWindow({
            content : iwContent,
            removable :iwRemoveable
            });
            
            // Display the info window on the marker
            infowindow.open(map, marker);

            // Change the map center coordinates to the connection location
            map.setCenter(locPosition);      
        }    
        </script>
        
    </body>

</html>