첨부파일 : 

map.htm




출처 : http://zero-gravity.tistory.com/154


   ↓ <head>와 </head>사이에 넣는다.

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>

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
35
36
37
38
39
40
41
42
43
44
45
46
47
<!-- GoogoleMap Asynchronously Loading the API ********************************************* -->
<script type="text/javascript">


      function initialize() {
        var mapLocation = new google.maps.LatLng('36.322473', '127.412501'); // 지도에서 가운데로 위치할 위도와 경도
        var markLocation = new google.maps.LatLng('36.322473', '127.412501'); // 마커가 위치할 위도와 경도
         
        var mapOptions = {
          center: mapLocation, // 지도에서 가운데로 위치할 위도와 경도(변수)
          zoom: 18, // 지도 zoom단계
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("map-canvas"), // id: map-canvas, body에 있는 div태그의 id와 같아야 함
            mapOptions);
         
        var size_x = 60; // 마커로 사용할 이미지의 가로 크기
        var size_y = 60; // 마커로 사용할 이미지의 세로 크기
         
        // 마커로 사용할 이미지 주소
        var image = new google.maps.MarkerImage( 'http://www.larva.re.kr/home/img/boximage3.png',
                            new google.maps.Size(size_x, size_y),
                            '',
                            '',
                            new google.maps.Size(size_x, size_y));
         
        var marker;
        marker = new google.maps.Marker({
               position: markLocation, // 마커가 위치할 위도와 경도(변수)
               map: map,
               icon: image, // 마커로 사용할 이미지(변수)
//             info: '말풍선 안에 들어갈 내용',
               title: '서대전네거리역이지롱~' // 마커에 마우스 포인트를 갖다댔을 때 뜨는 타이틀
        });
         
        var content = "이곳은 서대전네거리역이다! <br/> 지하철 타러 가자~"; // 말풍선 안에 들어갈 내용
         
        // 마커를 클릭했을 때의 이벤트. 말풍선 뿅~
        var infowindow = new google.maps.InfoWindow({ content: content});
 
        google.maps.event.addListener(marker, "click", function() {
            infowindow.open(map,marker);
        });
         
 
         
      }
      google.maps.event.addDomListener(window, 'load', initialize);
</script>



//위치 검색하기


  위치를 검색할 때, 위도와 경도로 찾게 되면 항상 미국 구글맵에 들어가서 위치를 검색한 다음에 위도와 경도를 알아내서 직접 기입해야 하는 수밖에 없는데... 이번 글에서는 그런 불편을 없애기 위해 위도/경도가 아닌 주소로 바로 검색하는 방법을 사용하려 한다.


   이 방법을 찾게 된 이유는 DB에 있는 수 십개의 업체들을 웹상에 지도로 표시해야 하는데 위도/경도 컬럼을 만들어서 일일히 업데이트 하는 게 지옥이었기 때문이다. 그래서 주소 컬럼을 이용해서 업체의 주소를 가져와 바로 검색할 수 있는 방법을 찾게 됐다. 구글맵API에서는 이걸 지오코딩이라고 부른다.


   전에도 말했지만 방법은 어렵지 않다.





※ 참고한 곳 

https://developers.google.com/maps/documentation/javascript/geocoding?hl=ko

https://developers.google.com/maps/documentation/javascript/examples/geocoding-simple?hl=ko


   참고했던 사이트를 보면, 구글에서는 주소 검색을 사용자가 직접 입력해 검색하는 방식으로 예제를 보여주는데, 아래 내가 한 방식은 미리 주소를 코딩해놓는 방식이다.





먼저 html doctype을 <!DOCTYPE html>로 변경해준 다음,

head 부분에

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>

추가해준다.


그리고..

↓ head에 삽입

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!-- GoogoleMap Asynchronously Loading the API ********************************************* -->
<script type="text/javascript">
    function initialize() {
     
        var mapOptions = {
                            zoom: 18, // 지도를 띄웠을 때의 줌 크기
                            mapTypeId: google.maps.MapTypeId.ROADMAP
                        };
         
         
        var map = new google.maps.Map(document.getElementById("map-canvas"), // div의 id과 값이 같아야 함. "map-canvas"
                                    mapOptions);
         
        var size_x = 40; // 마커로 사용할 이미지의 가로 크기
        var size_y = 40; // 마커로 사용할 이미지의 세로 크기
     
        // 마커로 사용할 이미지 주소
        var image = new google.maps.MarkerImage( '주소 여기에 기입!',
                                                    new google.maps.Size(size_x, size_y),
                                                    '',
                                                    '',
                                                    new google.maps.Size(size_x, size_y));
         
        // Geocoding *****************************************************
        var address = '대전광역시 중구 한밭도서관길 222'; // DB에서 주소 가져와서 검색하거나 왼쪽과 같이 주소를 바로 코딩.
        var marker = null;
        var geocoder = new google.maps.Geocoder();
        geocoder.geocode( { 'address': address}, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                map.setCenter(results[0].geometry.location);
                marker = new google.maps.Marker({
                                map: map,
                                icon: image, // 마커로 사용할 이미지(변수)
                                title: '한밭도서관', // 마커에 마우스 포인트를 갖다댔을 때 뜨는 타이틀
                                position: results[0].geometry.location
                            });
 
                var content = "한밭도서관<br/><br/>Tel: 042-580-4114"; // 말풍선 안에 들어갈 내용
             
                // 마커를 클릭했을 때의 이벤트. 말풍선 뿅~
                var infowindow = new google.maps.InfoWindow({ content: content});
                google.maps.event.addListener(marker, "click", function() {infowindow.open(map,marker);});
            } else {
                alert("Geocode was not successful for the following reason: " + status);
            }
        });
        // Geocoding // *****************************************************
         
    }
    google.maps.event.addDomListener(window, 'load', initialize);
</script>



↓body 안에 삽입

1
<div id="map-canvas" style="width: 100%; height: 340px" title="도서관 위치입니다."></div>


끝~!



출처 : http://blog.naver.com/jiho3400?Redirect=Log&logNo=10174180497


오늘은 구글 지도에 관해서 간단히 정리해 봤습니다.

google map v3 로 바뀌고 부터는 키 정보 필요없이 구글 지도 정보를 사용하는게 가능해졌는데요..

빙맵이나 다른 경쟁사와 비교해봐도 컨텐츠를 비롯해서 사용방법, 정보의 규모면등등 현존 쵝오 인듯 하네요...^^

 

그럼 구글 맵 간단히 시작하는 방법을 알아보겠습니다.

 

위의 이미지와 같은 지도를 만들어 보겠습니다.

먼저 google api 를 참조해서 넣어야겠죠. 단 당연한 말이겠지만 인터넷이 사용가능한 환경에서만 개발이 가능합니다..^^

먼저 head테그 내에 아래의 자바스크립트를 삽입합니다.

   1: <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>

이걸 삽입하면 이제 구글 지도 개발을 커스터마이징 하는게 가능합니다.

그럼 다음으로 자바스크립트를 적어보겠습니다.

   1: <script>
   2: var map;
   3: function initialize() {
   4:   var mapOptions = {
   5:     // 줌을 적용
   6:     zoom: 8,
   7:     // 지도의 중심지점을 설정
   8:     center: new google.maps.LatLng(-34.397, 150.644),
   9:     // 지도의 타입 설정
  10:     mapTypeId: google.maps.MapTypeId.ROADMAP
  11:   };
  12:   map = new google.maps.Map(document.getElementById('map-canvas'),
  13:       mapOptions);
  14: }
  15:  
  16: google.maps.event.addDomListener(window, 'load', initialize);
  17:  
  18:     </script>

이 자바스크립트를 위의 api바로 밑에 삽입합니다.

 

그리고 html에 타겟영역을 만들어주면 끝입니다.

 

   1: <div style="width:600px; height:400px;" id="map-canvas"></div>

지도를 삽입하고 싶은 html영역에 위 코드를 넣으면 끝입니다.

일단 크기는 600 * 400으로 넣었습니다만 원하시는 크기로 바꾸면 지도의 크기가 결정됩니다.

 

어때요? 참 쉽죠^^

 

그럼 시간날때 조금더 응용법을 올려보도록 하겠습니다.

아래는 여기까지의 완성된 소스 입니다.

   1: <!DOCTYPE html>
   2: <html>
   3:   <head>
   4:     <title>Simple Map</title>
   5:     <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
   6:     <meta charset="utf-8">
   7:     <style>
   8:       html, body, #map-canvas {
   9:         margin: 0;
  10:         padding: 0;
  11:         height: 100%;
  12:       }
  13:     </style>
  14:     <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script><pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white">   1:  </pre><pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4">   2:     <script></pre><pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white">   3: var map;</pre><pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4">   4: function initialize() {</pre><pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white">   5:   var mapOptions = {</pre><pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4">   6:     zoom: 8,</pre><pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white">   7:     center: new google.maps.LatLng(-34.397, 150.644),</pre><pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4">   8:     mapTypeId: google.maps.MapTypeId.ROADMAP</pre><pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white">   9:   };</pre><pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4">  10:   map = new google.maps.Map(document.getElementById('map-canvas'),</pre><pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white">  11:       mapOptions);</pre><pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4">  12: }</pre><pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white">  13:  </pre><pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4">  14: google.maps.event.addDomListener(window, 'load', initialize);</pre><pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white">  15:  </pre><pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4">  16:     </pre></script>
  15:   </head>
  16:   <body>
  17:     <div style="width:600px; height:400px;" id="map-canvas"></div>
  18:   </body>
  19: </html>

 


+ Recent posts