Google Places API를 이용한 주변 지역 정보 검색

Open API/Google|2016. 11. 22. 16:39
반응형



간만에 구글 API를 보던 중 재미난 샘플이 있어서 살짝 들여다 봤습니다.. 맛만..;;

화면 ui 및 기능 정리가 잘되어있어서 활용 범위가 클것같습니다.

Google Places 대신 자체 디비를 사용해서 쓰게되도 멋질것 같다는 생각이 듭니다.

( 메인은 Google Places 인데...어째 딴 생각이 드네요.)



아직 자세히 보지는 못해서 조만간 뜯어보고 싶네요.

복합적인 기능이다 보니 좀 단순화시켜서 개별 샘플화 하기!!

당장 하고 싶지만 일은 해야 하니까요 ㅠㅠ


보면 볼수록 구글의 방대한 데이터는..후덜덜하네요


Test Url : http://www.uhoon.co.kr/test/2253.html



대략 적인 기능은 


지역명 자동완성 기능 - Autocomplete

좌표 이동시 getBounds() 를 이용하여 화면내에 위치한 마커만 표시

PlacesService 로 지역정보 검색 등등.....   


API Url : https://developers.google.com/places/?hl=ko


참고 Url : https://developers.google.com/maps/documentation/javascript/examples/place-search?hl=ko




2014.06.06 추가 내용 :


기본 검색에 대해서 

 : https://developers.google.com/places/documentation/search?hl=ko


 

검색키워드는... 

 : https://developers.google.com/places/documentation/supported_types?hl=ko








댓글()

Google API GeoRSS 피드에서 KmlLayer를 생성..." geoRSS 로 레이어 마커 찍기 "

Open API/Google|2016. 11. 22. 16:35
반응형




GeoRss 포맷을 이용해서 레이어 마커를 생성하는 예제입니다..


TestUrl : http://www.uhoon.co.kr/test/1972.html


Google API Url : https://developers.google.com/maps/documentation/javascript/layers?hl=ko



용어 : 


* KML ( wiki 에서 : KMLViewer )
- 키홀 마크업 언어(Keyhole Markup Language, KML)은 구글 어스, 구글 지도 및 기타 응용 프로그램에 쓰이는 XML 기반의 마크업 언어 스키마이다.



*GeoRSS ( wiki 에서 : GeoRSSViewer )

- 위치를 인코딩하기위한 새로운 표준 웹 피드 





<!DOCTYPE html>
<html>

<head>
	<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
	<meta charset="utf-8">
	<title>GeoRSS Layers</title>
	<style type="text/css">
		html, body {
			height: 100%;
			margin: 0;
			padding: 0;
		}
		#map-canvas, #map_canvas {
			height: 100%;
		}
		@media print {
			html, body {
				height: auto;
			}
			#map-canvas, #map_canvas {
				height: 650px;
			}
		}
		#panel {
			position: absolute;
			top: 5px;
			left: 50%;
			margin-left: -180px;
			z-index: 5;
			background-color: #fff;
			padding: 5px;
			border: 1px solid #999;
		}
	</style>
	<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
	<script>
		function initialize() {
			var myLatlng = new google.maps.LatLng(49.496675, -102.65625);
			var mapOptions = {
				zoom: 4,
				center: myLatlng,
				mapTypeId: google.maps.MapTypeId.ROADMAP
			}
			var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
			var georssLayer = new google.maps.KmlLayer({
				url: 'http://www.uhoon.co.kr/test/1972/georss.xml'
			});
			georssLayer.setMap(map);
		}
		google.maps.event.addDomListener(window, 'load', initialize);
	</script>
</head>

<body>
	<div id="map-canvas"></div>
</body>

</html>


댓글()

Google API 구글맵 API 적용범위 (Google Maps API Coverage)

Open API/Google|2016. 11. 22. 16:32
반응형




Google Maps API Coverage


* Countries

- 국가/도시/맵타일

- 지오코딩/스트릿뷰

- 트래픽/드라이빙/비지니스리스팅/도메인/바이킹


* Languages

v2 , v3 버전별 지원 언어 및 코드

 

링크 : https://spreadsheets.google.com/pub?key=p9pdwsai2hDMsLkXsoM05KQ&gid=1


댓글()

google API 스트릿뷰 Street View

Open API/Google|2016. 11. 22. 16:30
반응형



스트릿뷰 샘플 소스입니다..


회사 앞으로 찾아봤는데 잘 나오네요 


기본형에다가 해당 위경도 , POV 값을표기하는 내용 추가했습니다.


API Url : https://developers.google.com/maps/documentation/javascript/streetview?hl=ko


Test Url : http://source.uhoon.co.kr/test/1957.html






<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>Street View service</title>
	<link href="https://developers.google.com/maps/documentation/javascript/examples/default.css" rel="stylesheet">
	<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
	<script>
		function initialize() {
			var fenway = new google.maps.LatLng(
				37.569303, 126.97943099999998);
			var mapOptions = {
				center: fenway,
				zoom: 14,
				mapTypeId: google.maps.MapTypeId.ROADMAP
			};
			var map = new google.maps.Map(
				document.getElementById(
					'map-canvas'), mapOptions);
			var panoramaOptions = {
				position: fenway,
				pov: {
					heading: 34,
					pitch: 10
				}
			};
			var panorama = new google.maps.StreetViewPanorama(
				document.getElementById('pano'),
				panoramaOptions);
			map.setStreetView(panorama);
			google.maps.event.addListener(
				panorama, 'links_changed', function () {
					var linksTable = document.getElementById(
						'links_table');
					while (linksTable.hasChildNodes()) {
						linksTable.removeChild(linksTable
							.lastChild);
					};
					var links = panorama.getLinks();
					for (var i in links) {
						var row = document.createElement(
							'tr');
						linksTable.appendChild(row);
						var labelCell = document.createElement(
							'td');
						labelCell.innerHTML = '<b>Link: ' +
							i + '</b>';
						var valueCell = document.createElement(
							'td');
						valueCell.innerHTML = links[i].description;
						linksTable.appendChild(labelCell);
						linksTable.appendChild(valueCell);
					}
				});
			google.maps.event.addListener(
				panorama, 'position_changed',
				function () {
					var positionCell = document.getElementById(
						'position_cell');
					positionCell.firstChild.nodeValue =
						panorama.getPosition() + '';
				});
			google.maps.event.addListener(
				panorama, 'pov_changed', function () {
					var headingCell = document.getElementById(
						'heading_cell');
					var pitchCell = document.getElementById(
						'pitch_cell');
					headingCell.firstChild.nodeValue =
						panorama.getPov().heading + '';
					pitchCell.firstChild.nodeValue =
						panorama.getPov().pitch + '';
				});
		}
		google.maps.event.addDomListener(
			window, 'load', initialize);
	</script>
</head>

<body>
	<div id="map-canvas" style="width: 400px; height: 300px"></div>
	<div id="pano" style="position:absolute; left:410px; top: 8px; width: 400px; height: 300px;"></div>
	<div id="panoInfo" style="width: 45%; height: 100%;float:left">
		<table>
			<tr>
				<td><b>Position</b>
				</td>
				<td id="position_cell"> </td>
			</tr>
			<tr>
				<td><b>POV Heading</b>
				</td>
				<td id="heading_cell">270</td>
			</tr>
			<tr>
				<td><b>POV Pitch</b>
				</td>
				<td id="pitch_cell">0.0</td>
			</tr>
			<tr>
				<td><b>Pano ID</b>
				</td>
				<td id="pano_cell"> </td>
			</tr>
			<table id="links_table"></table>
		</table>
	</div>
</body>

</html>




댓글()

Google API 현재 위경도 읽어와서 구글맵에 마커 표시하기 ( getCurrentPosition )

Open API/Google|2016. 11. 22. 16:26
반응형



현재 위치를 읽어와서 구글맵에 마커를 표시해주는 기능입니다.


Test Url : http://www.uhoon.co.kr/test/1208.html



<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>getCurrentPosition + Googlemap marker </title>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script type="text/javascript">
<!--
    function fnGetCurrentPosition() {
        if (navigator.geolocation)
        {
            $("#latlng").html("");
            $("#errormsg").html("");
            navigator.geolocation.getCurrentPosition (function (pos)
            {
                lat = pos.coords.latitude;
                lng = pos.coords.longitude;
 
                $("#latlng").html("latitude : " + lat + "
 longitude : "+ lng);
 
                var mapOptions = {
                    zoom: 16,
                    mapTypeId: google.maps.MapTypeId.ROADMAP,
                    center: new google.maps.LatLng(lat,lng)
                };
 
                map = new google.maps.Map(document.getElementById('map'),mapOptions);
 
                var myIcon = new google.maps.MarkerImage("http://google-maps-icons.googlecode.com/files/restaurant.png", null, null, null, new google.maps.Size(17,17));
                var marker = new google.maps.Marker({
                    position: new google.maps.LatLng(lat,lng),
                    map: map,
                    draggable: false,
                    icon: myIcon
                });
                markers.push(marker);
            },function(error)
            {
                switch(error.code)
                {
                    case 1:
                        $("#errormsg").html("User denied the request for Geolocation.");
                        break;
                    case 2:
                        $("#errormsg").html("Location information is unavailable.");
                        break;
                    case 3:
                        $("#errormsg").html("The request to get user location timed out.");
                        break;
                    case 0:
                        $("#errormsg").html("An unknown error occurred.");
                        break;
                }
            });
        }
        else
        {
            $("#errormsg").html("Geolocation is not supported by this browser.");
        }
    }
//-->
</script>
</head>
<body>
<div id="errormsg"></div>
<div id="latlng"></div>
<input type="button" value="GetCurrentPosition " onclick="Javascript:fnGetCurrentPosition();" />
<div id="map" style="width:760px;height:400px;margin-top:20px;"></div>
</body>
</html>


getCurrentPosition 자세히 알아보기 : http://www.uhoon.co.kr/API/1200




댓글()

Google API 구글맵 출발지 도착지 주소입력해서 길찾기 - v3

Open API/Google|2016. 11. 21. 18:18
반응형



지명 또는 주소를 입력해서 

이동 수단 별 이동 경로를 알려주는 기능


국내 Driving , Walking 은 잘 안되는듯함...Transit 은 잘 됨..


Test Url : http://www.uhoon.co.kr/test/872.html



<!DOCTYPE html>
<html>
    <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <title>Directions service</title>
    <style type="text/css">
        html, body {
          height: 100%;
          margin: 0;
          padding: 0;
        }
 
        #map-canvas, #map_canvas {
          height: 100%;
        }
 
        @media print {
          html, body {
            height: auto;
          }
 
          #map_canvas {
            height: 650px;
          }
        }
 
        #panel {
          position: absolute;
          top: 5px;
          left: 50%;
          margin-left: -180px;
          z-index: 5;
          background-color: #fff;
          padding: 5px;
          border: 1px solid #999;
        }
    </style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
    <script>
    var directionsDisplay;
    var directionsService = new google.maps.DirectionsService();
    var map;
 
    function initialize() {
      directionsDisplay = new google.maps.DirectionsRenderer();
      var chicago = new google.maps.LatLng(41.850033, -87.6500523);
      var mapOptions = {
        zoom:7,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        center: chicago
      }
      map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
      directionsDisplay.setMap(map);
    }
 
    function calcRoute() {
      var start = document.getElementById('start').value;
      var end = document.getElementById('end').value;
      var mode = document.getElementById('mode').value;
 
      var request = {
          origin:start,
          destination:end,
          travelMode: eval("google.maps.DirectionsTravelMode."+mode)
      };
      directionsService.route(request, function(response, status) {
        alert(status);  // 확인용 Alert..미사용시 삭제
        if (status == google.maps.DirectionsStatus.OK) {
            directionsDisplay.setDirections(response);
        }
      });
    }
 
    google.maps.event.addDomListener(window, 'load', initialize);
 
    </script>
    </head>
    <body>
        <div id="panel" >
            <b>Start: </b>
            <input type="text" id="start" />
            <b>End: </b>
            <input type="text" id="end" />
            <div>
                <strong>Mode of Travel: </strong>
                <select id="mode">
                <option value="DRIVING">Driving</option>
                <option value="WALKING">Walking</option>
                <option value="BICYCLING">Bicycling</option>
                <option value="TRANSIT">Transit</option>
                </select>
                <input type="button" value="길찾기" onclick="Javascript:calcRoute();" />
            </div>
        </div>
        <div id="map-canvas"></div>
    </body>
</html>


댓글()

Google API 구글맵 아이콘 마커 + 말풍선 + 주소로 위경도 검색 + 거리별 원그리기 - v3

Open API/Google|2016. 11. 21. 18:16
반응형



구글맵 V3 기본 기능입니다..

다음번에는 길찾기 등...animation 쪽으로..


Test Url : http://www.uhoon.co.kr/test/613.html



* 기능

 기본 맵

 아이콘 마커 (marker)

 말풍선 (infoWindow)

 주소로 위경도 검색하기 (geocoder)

 거리별 중심점 기준으로 원그리기 ( Circle )



<!doctype html>
<html>
<head>
	<meta charset="utf-8" />
	<title>googlemap v3 </title>
	<script src="http://code.jquery.com/jquery-latest.min.js"></script>
	<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
</head>
<SCRIPT LANGUAGE="JavaScript">
<!--
var contentArray = [];
var iConArray = [];
var markers = [];
var iterator = 0;
var map;
var geocoder;

// infowindow contents 배열
 contentArray[0] = "Kay";
 contentArray[1] = "uhoons blog";
 contentArray[2] = "blog.uhoon.co.kr";
 contentArray[3] = "www.suvely.com";
 contentArray[4] = "www.babbabo.com";
 contentArray[5] = "blog.goodkiss.co.kr";
 contentArray[6] = "GG";
 contentArray[7] = "blog.goodkiss.co.kr";
 contentArray[8] = "II";
 contentArray[9] = "blog.goodkiss.co.kr";

// marker icon 배열
 iConArray[0] = "http://google-maps-icons.googlecode.com/files/walking-tour.png";
 iConArray[1] = "http://google-maps-icons.googlecode.com/files/walking-tour.png";
 iConArray[2] = "http://google-maps-icons.googlecode.com/files/walking-tour.png";
 iConArray[3] = "http://google-maps-icons.googlecode.com/files/walking-tour.png";
 iConArray[4] = "http://google-maps-icons.googlecode.com/files/walking-tour.png";
 iConArray[5] = "http://google-maps-icons.googlecode.com/files/walking-tour.png";
 iConArray[6] = "http://google-maps-icons.googlecode.com/files/walking-tour.png";
 iConArray[7] = "http://google-maps-icons.googlecode.com/files/walking-tour.png";
 iConArray[8] = "http://google-maps-icons.googlecode.com/files/walking-tour.png";
 iConArray[9] = "http://google-maps-icons.googlecode.com/files/walking-tour.png";

// 위경도 배열
var markerArray = [ new google.maps.LatLng(40.3938,-3.7077)
, new google.maps.LatLng(40.45038,-3.69803)
, new google.maps.LatLng(40.45848,-3.69477)
, new google.maps.LatLng(40.40672,-3.68327)
, new google.maps.LatLng(40.43672,-3.62093)
, new google.maps.LatLng(40.46725,-3.67443)
, new google.maps.LatLng(40.43794,-3.67228)
, new google.maps.LatLng(40.46212,-3.69166)
, new google.maps.LatLng(40.41926,-3.70445)
, new google.maps.LatLng(40.42533,-3.6844)
];

function initialize() {
	geocoder = new google.maps.Geocoder();

	var mapOptions = {
		zoom: 11,
		mapTypeId: google.maps.MapTypeId.ROADMAP,
		center: new google.maps.LatLng(40.4167754,-3.7037901999999576)
	};

	map = new google.maps.Map(document.getElementById('map'),mapOptions);

	var populationOptions = {
		strokeColor: '#000000',
		strokeOpacity: 0.8,
		strokeWeight: 2,
		fillColor: '#808080',
		fillOpacity: 0.5,
		map: map,
		center: new google.maps.LatLng(40.4167754,-3.7037901999999576) ,
		radius: $("#radius").val()*1000
	};
	cityCircle = new google.maps.Circle(populationOptions);
}

// 주소 검색
function showAddress() {
	var address = $("#address").val();
	geocoder.geocode( { 'address': address}, function(results, status) {
		if (status == google.maps.GeocoderStatus.OK) {
			map.setCenter(results[0].geometry.location);
			var marker = new google.maps.Marker({
				map: map,
				position: results[0].geometry.location,
				draggable: true
			});

			google.maps.event.addListener(marker, "dragend", function(event) {
				var point = marker.getPosition();
				$("#latitude").val(point.lat());
				$("#longitude").val(point.lng());

				var populationOptions = {
					strokeColor: '#000000',
					strokeOpacity: 0.8,
					strokeWeight: 2,
					fillColor: '#808080',
					fillOpacity: 0.5,
					map: map,
					center: new google.maps.LatLng($("#latitude").val(),$("#longitude").val()) ,
					radius: $("#radius").val()*1000
				};
				if (cityCircle)
				{
					cityCircle.setMap(null);
				}
				cityCircle = new google.maps.Circle(populationOptions);
			});

			var lat = results[0].geometry.location.lat();
			var lng = results[0].geometry.location.lng();

			$("#latitude").val(lat);
			$("#longitude").val(lng);

			var populationOptions = {
				strokeColor: '#000000',
				strokeOpacity: 0.8,
				strokeWeight: 2,
				fillColor: '#808080',
				fillOpacity: 0.5,
				map: map,
				center: new google.maps.LatLng(lat,lng) ,
				radius: $("#radius").val()*1000
			};
			if (cityCircle)
			{
				cityCircle.setMap(null);
			}
			cityCircle = new google.maps.Circle(populationOptions);

		} else {
			alert('Geocode was not successful for the following reason: ' + status);
		}
	});
}

// 드롭 마커 보기
function viewMarker() {
	for (var i = 0; i < markerArray.length; i++) {
		setTimeout(function() {
			addMarker();
		}, i * 300);
	}

	var marker = new google.maps.Marker ({
			position: new google.maps.LatLng(40.4167754,-3.7037901999999576),
			map: map,
			draggable: true
		});

	google.maps.event.addListener(marker, "dragend", function(event) {
		var point = marker.getPosition();
		$("#latitude").val(point.lat());
		$("#longitude").val(point.lng());

		var populationOptions = {
			strokeColor: '#000000',
			strokeOpacity: 0.8,
			strokeWeight: 2,
			fillColor: '#808080',
			fillOpacity: 0.5,
			map: map,
			center: new google.maps.LatLng($("#latitude").val(),$("#longitude").val()) ,
			radius: $("#radius").val()*1000
		};
		if (cityCircle)
		{
			cityCircle.setMap(null);
		}
		cityCircle = new google.maps.Circle(populationOptions);
	});
}

// 마커 추가
function addMarker() {

	var marker = new google.maps.Marker({
		position: markerArray[iterator],
		map: map,
		draggable: false,
		icon: iConArray[iterator],
		animation: google.maps.Animation.DROP
	});
	markers.push(marker);

	var infowindow = new google.maps.InfoWindow({
      content: contentArray[iterator]
	});

	google.maps.event.addListener(marker, 'click', function() {
		infowindow.open(map,marker);
	});
	iterator++;
}

// 중심 이동
function fnLocation(lat, lng) {
	myLocation = new google.maps.LatLng(lat, lng);
	map.setCenter(myLocation);
}

//google.maps.event.addDomListener(window, 'load', initialize);

$( window ).load(function() {
	initialize();
	viewMarker();
});

//-->
</SCRIPT>
<body>
radius : <select id="radius" >
	<option value="10" selected="selected">10Km</option>
	<option value="5">5Km</option>
</select>
latitude : <input type="text" id="latitude" value="40.4167754"/>
longitude: <input type="text" id="longitude" value="-3.7037901999999576"/>
<div id="map" style="width:760px;height:400px;margin-top:20px;"></div>
<label style="margin:3px 0 0 0;" for="address">address</label>
<input type="text" id="address" name="address" style="margin:3px 0 0 5px;" value=""/>
<input type="button" value="search" onclick="Javascript:showAddress();" />
</body>
</html>


댓글()

Google API geocode - 주소로 위경도 검색 v3

Open API/Google|2016. 11. 21. 18:12
반응형



geocode - 주소를 통한 위경도 조회하기 입니다. 

  

Test Url : http://www.uhoon.co.kr/test/602.html




<!doctype html>
<html>
<head>
    <meta charset="utf-8" />
    <title>googlemap v3 geocoder</title>
    <script src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
</head>
<script type="text/javascript">
<!--
    $(function() {
        $("#getBtn").on("click", function(){ 
            var geocoder = new google.maps.Geocoder(); 
            var address = $("#address").val();
            geocoder.geocode( { 'address': address}, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    //var latLng = results[0].geometry.location;   
                    var lat = results[0].geometry.location.lat();
                    var lng = results[0].geometry.location.lng();
                    $("#lat").html(lat);
                    $("#lng").html(lng);
                }
            });
        });
    });
//-->
</script>
<body> 
<div>
    <input type="text" id="address" /><input type="button" value="get Lat,Lng" id="getBtn" />
</div>
<div>
    lat : <span id="lat"></span>
</div>
<div>
    lng : <span id="lng"></span>
</div>
</body>
</html>


댓글()