모바일 Atlan App 연동모바일로 보기

Atlan App과 연동 할 수 있는 샘플입니다.

 지도에서 위치를 선택해 주세요.     

Sample map

  Javascript

											
	var geocoder, map, geocodeType = 0, poiMarker = null;

	var userAgent = navigator.userAgent.toLocaleLowerCase();

	var poiName = null;
	var poiCoord = null;
	var xmlHttp;

	var auth_key = "YOUR_KEY";

	function createXMLHttpRequest() {

		try { // Opera 8.0+, Firefox, Chrome, Safari
			xmlHttp = new XMLHttpRequest();
		} catch (e) { // Internet Explorer Browsers
			try {
				xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {
					// Something went wrong
					alert("Your browser broke!");
					return false;
				}
			}
		}

	}

	function resizeMap() {
		var winHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
		var mapHeight = winHeight - 120;
		document.getElementById('map').style.height = mapHeight + "px";
	}

	window.onload = function() {
		resizeMap();
		map = new atlan.maps.Map('map', {
			center : new atlan.maps.UTMK(953933.75, 1952050.75),
			zoom : 7
		});

		poiMarker = new atlan.maps.overlay.Marker({
			visible : false,
			position : new atlan.maps.UTMK(953933.75, 1952050.75),
			map : map
		});

		geocoder = new atlan.maps.local.Geocoder(auth_key);

		map.onEvent("click", coord2poi);

		document.getElementById("btnStartApp").addEventListener("click", function(event){
		    event.preventDefault();
		    coord2cipher();
		});
	}

	/*
	 * #########################################
	 * [리버스 지오 코딩] - 좌표 -> 주소 변환
	 * #########################################
	 */

	function coord2poi(event) {
		var coord = event.getCoord();
		poiCoord = coord;

		// geocoder = new atlan.maps.local.Geocoder(auth_key);
		geocoder.coord2poi({
			type : 1,
			x : coord.x,
			y : coord.y
		}, "coord2poi_callback");
		poiMarker.setOptions({
			position : coord,
			caption : ''
		});
	}

	function coord2poi_callback(data) {
		//var geocoderResult = geocoder.parseGeocode(data);
		var jsonData = data;
		if (jsonData.ItemCnt != "0") {
			console.log(jsonData.Item[0].PoiStr);
			var _poiName = jsonData.Item[0].PoiStr;
			/*
			poiMarker.setOptions({
				caption : _poiName
			});
			*/
			document.getElementById('poiName').innerHTML = _poiName;
			poiName = _poiName;
			if (!poiMarker.isVisible()) {
				poiMarker.setVisible(true);
			}
		} else {
			alert("검색 결과가 없습니다.");
		}
	}

	function coord2cipher() {
		if (poiCoord == null) {
			alert('먼저 지도에서 위치를 선택해 주세요.');
			return false;
		}
		var _poiCoord = poiCoord.transform(atlan.maps.LatLng);

		var queryString = '';
		queryString += '&coordX=' + _poiCoord.x + '&coordY=' + _poiCoord.y

		// 좌표 암호화 요청
		var ajaxURL = "http://apis.atlan.co.kr/geo/coord2cipher.json?" + queryString;
		console.log(ajaxURL);

		createXMLHttpRequest();
		xmlHttp.onreadystatechange = coord2cipher_callback;
		xmlHttp.open("GET", ajaxURL, true);
		xmlHttp.send(null);

		return false;
	}

	function coord2cipher_callback() {
		if (xmlHttp.readyState == 4) {
			if (xmlHttp.status == 200) {
				if (xmlHttp.responseText.length > 0) {
					var jsonData = JSON.parse(xmlHttp.responseText);
					console.dir(jsonData);
					if (jsonData.ErrorCode == "000") {
						console.log(jsonData.result);
			
						var marketUrl = "market://details?id=kr.mappers.AtlanSmart";
						var appStartUrl = "intent://route/#Intent;scheme=linkatlan;package=kr.mappers.AtlanSmart;S.DestiShareType=sms;"
								+ "S.PoiCoordX=" + jsonData.result.x + ";S.PoiCoordY=" + jsonData.result.y
								+ ";S.Poiname=" + poiName + ";S.Poiid=;S.ButtonType=findroute;end";
						if (userAgent.search("iphone") > -1) {
							marketUrl = "http://itunes.apple.com/kr/app/ateullan-keullaudeunaebi/id542287735?mt=8";
							appStartUrl = "AtlanSmart://?DestiShareType=sms"
									+ "&PoiCoordX=" + jsonData.result.x + "&PoiCoordY=" + jsonData.result.y
									+ "&Poiname=" + poiName + "&Poiid=&ButtonType=findroute";
						}
						console.log(marketUrl);
						console.log(appStartUrl);
			
						var clickedAt = +new Date;
						setTimeout(
							function() {
								if (+new Date - clickedAt < 2000) {
									//$("#AtlanCloud").attr("src", marketUrl);
									document.getElementById("AtlanCloud").src = marketUrl;
								}
							}, 500);
			
						location.href = appStartUrl;
					} else {
						alert("좌표값을 확인할 수 없습니다.");
					}
				}
			}
		}
	}