1. Google API 인증키 얻기
- 링크 : https://code.google.com/apis/console
2. Google Map API
- 링크 : https://developers.google.com/maps/documentation/javascript/tutorial
3. 해당 소스
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | <p style= "text-align: center;" ><button id= "getLocation" type= "button" >위치 정보 수집</button></p> <p style= "text-align: center;" ><br></p> <p style= "text-align: center;" ></p> <div style= "text-align: center;" ><div id= "map" style= "width: 500px; height: 500px; display: inline-block; text-align: center;" ></div></div><p> </p> <script> ( function () { let map, infoWindow; window.initMap = function () { map = new google.maps.Map(document.getElementById( 'map' ), { center: {lat: -34.397, lng: 150.644}, zoom: 8 }); infoWindow = new google.maps.InfoWindow({map: map}); infoWindow.setContent( 'Your location' ); }; function successCallback(position) { let pos = { lat: position.coords.latitude, lng: position.coords.longitude }; infoWindow.setPosition(pos); map.setCenter(pos); alert( "Your current position is: latitude(" + pos.lat + "), longitude(" + pos.lng + ")" ); } function errorCallback(error) { alert( "Error: " + error.message); } document.getElementById( "getLocation" ).onclick = function () { navigator.geolocation.getCurrentPosition(successCallback, errorCallback); }; }()); </script> <script src= "https://maps.googleapis.com/maps/api/js?key={$API_KEY}&callback=initMap" async= "" defer= "" ></script> |