¿ÀÂAPI

Version 1.0 야후! 지도 정류장 검색 API

중심 좌표를 기준으로하여 특정 거리 이내의 버스정류장/지하철역 정보를 검색 할 수 있습니다.

한번 호출에 최대 200개의 정류장을 반환 합니다.

요청 URL

http://kr.open.gugi.yahoo.com/service/getstationbyrec.php

아래의 예제는 이전에 작성한 코드를 일부 수정하여 window.onLoad 이벤트를 이용, 지도를 초기화 시키고, 정류장 정보를 보여주는 예제입니다.

<html>
<head>
<script type="text/javascript" src="http://kr.open.gugi.yahoo.com/Client/AjaxMap.php?v=3.7&appid=YahooDemo"></script>
<style type="text/css">
#map{
height: 75%;
width: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<div id="station"></div>
<script type="text/javascript">
	// Create a Map that will be placed in the "map" div.
	var map = new YMap(document.getElementById('map'));
	function startMap(){
		// Add the ability to change between Sat, Hybrid, and Regular Maps
		map.addTypeControl();
		// Add the zoom control. Long specifies a Slider versus a "+" and "-" zoom control
		map.addZoomLong();
		// Add the Pan control to have North, South, East and West directional control
		map.addPanControl();
		// Add an event to report to getstationinfo
		YEvent.Capture(map, EventsList.endMapDraw, getStationInfo);
		// Specifying the Map starting location and zoom level
		map.drawZoomAndCenter(encodeURIComponent("야후 코리아"), 1);
	}
	//Event handler
	function getStationInfo(lat,lon){
		var _cLat=map.getCenterLatLon().Lat;
		var _cLon=map.getCenterLatLon().Lon;
		var z=map.getZoomLevel();
		var _id=YUtility.getRandomID();	//make randome dom id.
		var url="http://kr.open.gugi.yahoo.com/service/getstationbyrec.php?appid=YahooDemo&output=json&callback=handle_response&latitude="+_cLat+"&longitude="+_cLon+"&distance=0.5&zoom="+z;
		YUtility.dynamicSNode(_id,url); //make dynamic javascript for using json-callback.
	}
	//response handler
	function handle_response(result){
		if(typeof(result)=="object"){
			var h=result["ResultSet"]["head"];
			var b=result["ResultSet"]["body"];
			if(parseInt(h["Error"])<1){	//error check
				var stations=b["station"];
				for(i=0;i<stations.length;i++){
					_type=stations[i]["type"];
					_name=stations[i]["name"];
					_geo=stations[i]["geo"];
					_no=stations[i]["no"];
					newMarker= new YMarker(new YGeoPoint(_geo["latitude"],_geo["longitude"]));
					newMarker.addAutoExpand(_name+"<br>"+_no);
					map.addOverlay(newMarker);
				}
			}
		}
	}
	window.onload = startMap;
</script>
</body>
</html>

예제 실행

요청 파라미터들

파라미터 설명
appid 문자 (필수) 지도 API키(Key) 값. 지도 API키 신청/확인하기
encoding 문자: utf-8 (기본값), euc-kr 검색어의 언어코드를 지정한다. 지정되어 있지 않을 때는 기본값으로 utf-8을 사용한다.
output 문자: xml (default), json, php 리턴 받고자 하는 데이터의 형식
callback 문자 JSON 데이터를 감싸는 콜벡 함수의 이름. 값은 A-Z a-z 0-9사이의 값이 허용된다. output이 json이 아닌 경우는 결과에 아무런 영향을 끼치지 않는다.
latitude 숫자 (필수) 정류장 검색을 하고자 하는 중심 좌표의 위도.
longitude 숫자 (필수) 정류장 검색을 하고자 하는 중심 좌표의 경도.
zoom 정수, 1~7 (필수) 표현하고자하는 지도의 줌 레벨.
distance 숫자, 0.1 ~ 10(단위=km) (필수) 중심좌표(GeoPoint)를 기준으로하여 정사각 바운더리를 설정하기 위한 거리. 범위 초과시 10(km)로 지정됨.
type 문자 : A (기본값),B A : Link포함 데이터 (xml type 1참조)
B : Text 형식 데이터 (xml type 2참조)

Sample Request Url:
http://kr.open.gugi.yahoo.com/service/getstationbyrec.php?appid=YahooDemo&latitude=37.4997677193116&longitude=127.0294189453125&output=xml&distance=0.2&zoom=4

응답 항목들

항목 설명
publisher 배포자 이름
Error 0보다 큰 경우 에러가 1가지 이상 존재한다는 의미임. 0또는 음수 인 경우 성공.
ErrorMessage 오류에 대한 상세 메시지
Found 결과물의 개수
moreinfo 추가 정보를 위한 링크
station 정류장 상세 정보를 담고 있는 항목 요소
index 일련 번호(정렬 등에서 사용 가능한 번호, 1~200)
type 정류장 구분 : B=버스정류장, M=지하철역
name 정류장 이름
geo 정류장 위도와 경도.
no 버스번호 혹은 지하철 역 정보(들)
title B Type 결과에서 버스 번호 혹은 지하철 역 정보
kind B Type 결과에서 버스인 경우 버스 종류
icon B Type 결과에서 버스인 경우 버스 종류 아이콘 URL
url 해당 정보에 대한 상세 서비스 URL

샘플 응답

Type 1, 기본 응답 샘플

Type 2, Text위주의 응답 샘플


Version 1.0 야후! 지도 정류장 보기 API

현재 지도의 중심 좌표를 기준으로 버스정류장/지하철역 정보를 검색후 자동으로 YMarker를 추가해 보여주는 API.

1~3레벨을 지원 하며, 한번 호출에 최대 200개의 정류장을 반환 합니다.

아래의 예제는 이전에 작성한 코드를 일부 수정하여 window.onLoad 이벤트를 이용, 지도를 초기화 시키고, 정류장 정보를 보여주는 예제입니다.

<html>
<head>
<script type="text/javascript" src="http://kr.open.gugi.yahoo.com/Client/AjaxMap.php?v=3.7&appid=YahooDemo"></script>
<style type="text/css">
#map{
height: 75%;
width: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<div id="station"></div>
<script type="text/javascript">
	// Create a Map that will be placed in the "map" div.
	var map = new YMap(document.getElementById('map'));
	function startMap(){
		// Add the ability to change between Sat, Hybrid, and Regular Maps
		map.addTypeControl();
		// Add the zoom control. Long specifies a Slider versus a "+" and "-" zoom control
		map.addZoomLong();
		// Add the Pan control to have North, South, East and West directional control
		map.addPanControl();
		// Specifying the Map starting location and zoom level
		map.drawZoomAndCenter(encodeURIComponent("야후 코리아"), 1);
	}
	window.onload = startMap;
	//Create a station object that will be manage current stations.
	var st;
	st=new GetStations(map);
	function drawST(){
	  var result=st.drawStation();
	  if(result!=1){
	    alert("지원하지 않는 줌 레벨 입니다.");
	  }
	}
	function clearST(){
	  if(st!=null) st.clearSMarker();
	}
	function getSTOBJ(){
	  if(st!=null) alert(st.getSMarkerObject());
	}
</script>
<input type="button" name="button1" onclick="drawST();" value="정류장 보이기">
<input type="button" name="button2" onclick="clearST();" value="정류장 지우기">
<input type="button" name="button3" onclick="getSTOBJ();" value="정류장 Object 가져오기">
</body>
</html>

예제 실행

Class

Station

Constructor

GetStations(mapobject)

Methods

메소드 설명
drawStation(callback) 현재 지도위에 정류장 마커 생성, callback함수 재정의 가능

Return value :
  • -1 = 줌 레벨이 1~3레벨이 아님
  •  1 = 성공
getSMarkerObject 현재 지도위의 정류장 마커를 Object 배열 형태로 추출

Return value :
  • array, 정류장 마커 Object.
clearSMarker 현재 지도위의 모든 정류장 마커를 제거

Return value :
  • void

Version 1.0 야후! 지도 대중교통, 실시간 길찾기 API

지점간 대중교통 검색 및 실시간 도로 상황을 반영한 빠른길찾기 검색 API

아래의 예제는 이전에 작성한 코드를 일부 수정하여 window.onLoad 이벤트를 이용, 지도를 초기화 시키고, 길찾기 Form을 생성하는 예제입니다.

<html>
<head>
<script type="text/javascript" src="http://kr.open.gugi.yahoo.com/Client/AjaxMap.php?v=3.7&appid=YahooDemo"></script>
<style type="text/css">
#map{
height: 75%;
width: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<div id="station"></div>
<script type="text/javascript">
	// Create a Map that will be placed in the "map" div.
	var map = new YMap(document.getElementById('map'));
	function startMap(){
		// Add the ability to change between Sat, Hybrid, and Regular Maps
		map.addTypeControl();
		// Add the zoom control. Long specifies a Slider versus a "+" and "-" zoom control
		map.addZoomLong();
		// Add the Pan control to have North, South, East and West directional control
		map.addPanControl();
		// Specifying the Map starting location and zoom level
		map.drawZoomAndCenter(encodeURIComponent("야후 코리아"), 1);
		var newMarker= new YMarker(encodeURIComponent("야후 코리아"));
		newMarker.addAutoExpand("야후 코리아");
		map.addOverlay(newMarker);
	}
	window.onload = startMap;
</script>
<h1>Sample 1. 도착지를 지정한 경우</h1>
<form name="myform">
출발지 <input type="text" name="p1" value="" /> ▷ 야후 코리아 
<input type="button" name="button1" onclick="GetRoutingURL(this.form.p1.value,'야후 코리아',new YGeoPoint(37.507430299682,127.05590286313),'R');" value="자가용으로 찾아오기"><br>
<h1>Sample 2. 출발지, 도착지가 지정되지 않은 경우</h1>
출발지 <input type="text" name="p2" value="" /> ▷ 도착지 
<input type="text" name="p3" value="" /> <input type="button" name="button2" onclick="GetRoutingURL(this.form.p2.value,this.form.p3.value,'','P');" value="대중교통 길찾기"><br>
</form>
</body>
</html>

예제 실행

함수명

GetRoutingURL(p1,p2,YGeoPoint,type)

요청 파라미터들

파라미터 설명
p1 문자 출발지 검색어
p2 문자 도착지 검색어
GeoPoint YGeoPoint 도착지의 위도/경도 오브젝트인 YGeoPoint
routing type 문자, p(대중교통, 기본값), R(실시간교통) 경로 검색 종류
개인정보/청소년보호 정책
책임의 한계와 법적고지
서비스 약관
서비스 제안/질문
야후! 지도 바로가기

Copyright © 2009 Yahoo! Korea LLC. All rights reserved.