테스트 사이트 - 개발 중인 베타 버전입니다

[ PHP ] Geoip , 지도에서 아이피위치 불러오기

· 7년 전 · 4742 · 1

구글지도에서 아이피 위치를 표시해줍니다.

 

<div id="map"></div>
   <script>
      function initMap() {
        var map = new google.maps.Map(document.getElementById('map'), {
          center: {lat: -34.397, lng: 150.644},
          zoom: 15
        });
        var infoWindow = new google.maps.InfoWindow({map: map});

        // Try HTML5 geolocation.
        if (navigator.geolocation) {
          navigator.geolocation.getCurrentPosition(function(position) {
            var pos = {
              lat: position.coords.latitude,
              lng: position.coords.longitude
            };

            infoWindow.setPosition(pos);
            infoWindow.setContent('현 위치');
            map.setCenter(pos);
          }, function() {
            handleLocationError(true, infoWindow, map.getCenter());
          });
        } else {
          // Browser doesn't support Geolocation
          handleLocationError(false, infoWindow, map.getCenter());
        }
      }

      function handleLocationError(browserHasGeolocation, infoWindow, pos) {
        infoWindow.setPosition(pos);
        infoWindow.setContent(browserHasGeolocation ?
                              'Error: 서비스에 에러가 발생했습니다. 브라우저의 위치권한을 허용해주세요.' :
                              'Error: 브라우저 호환성이 떨어집니다. 크롬으로 바꾸는건 어떤가요?');
      }
    </script>
    <script async defer
    src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBfIM2TFBCJ-sf6MFz-eobXsWk2NU1ec70&callback=initMap">
    </script>
    

 

위치추적도 만들수 있을거같아요 네비게이션..??

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기

댓글 1개

7년 전
API키 공개되어있습니다...!!

게시글 목록

번호 제목
24318
24317
24315
24309
24294
24293
24277
24262
24260
24253
24251
24236
24233
24228
24226
24221
24214
24203
24201
24199
24196
24195
24194
24192
24191
24187
24185
24183
24172
24168