팝업 프린트 후 창 자동 닫기

Open API/그 외 |2018. 9. 14. 11:05
반응형

modal 팝업 , 일반 팝업 , 레이어 팝업 등등..온갖 팝업이 난무하는데


프린트하기가 너무 힘든 상황 통합으로 사용하기 위해서 방법을 찾아봤습니다.


어떤 경우 어떤 브라우저 버전에서는 


window.print() 후 window.close() 하면 


프린트 창이 뜨기도 전에 창이 닫히는 상황이 발생하기도하고..


포인트는 출력 후 onfocus 되었을때 창을 닫는다는 것.


최종 적으로는 아래 글에서 내용을 찾아서 처리했습니다.


여러 상황에 히스토리를 갖고 수정방법이 나열되어있습니다.


https://code-examples.net/en/q/6294d6


var content = "Hello";


newWin= window.open();

newWin.document.open();

newWin.document.write(content);

newWin.document.close();

setTimeout(function(){

	newWin.print();

	newWin.onfocus=function(){ newWin.close();}

},500);




댓글()

ip 주소로 국가 조회하는 방법 about.ip2c.org API

Open API/그 외 |2018. 8. 30. 17:08
반응형

아이피주소로 국가 조회하기


서비스하는 내용이 국가별로 제한되는 부분이라


DB를 구축하자니 그 업데이트관리가 문제이고


API가 있지 않을까 해서 구글링을 통해 알게된 사이트입니다.



https://about.ip2c.org



Request : 


https://ip2c.org/8.8.8.8


Response : 


1;US;USA;United States


; 로 구분자가 지정되어있으며


0 : WRONG INPUT , 1 : NORMAL , 2 : UNKNOWN 


US : ISO 국가코드 








아래 내용은 about.ip2c.org 사이트에서 발췌한 INPUT/OUTPUT 설명입니다.

 
==== Accepted inputs: ============================================================

You can use http or https.

https://ip2c.org/XXX.XXX.XXX.XXX
or
https://ip2c.org/?ip=XXX.XXX.XXX.XXX
|
+ standard IPv4 from 0.0.0.0 to 255.255.255.255
+ e.g. we take your IP:
    |
    + URL looks like this:  https://ip2c.org/128.134.3.161
    |                       or
    |                       https://ip2c.org/?ip=128.134.3.161
    |
    + resulting string is:  1;KR;KOR;Korea Republic of


https://ip2c.org/XXXXXXXXXX
or
https://ip2c.org/?dec=XXXXXXXXXX
|
+ decimal number from 0 to 4294967295 (MAX_INT)
+ faster than ?ip= option, less server-side processing
+ to convert IPv4 to decimal you only need to know this:
    |
    + (IPv4) A.B.C.D == A*256^3 + B*256^2 + C*256 + D (decimal)
    + e.g.   5.6.7.8 == 5*256^3 + 6*256^2 + 7*256 + 8
                     == 5*16777216 + 6*65536 + 7*256 + 8
                     == 83886080 + 393216 + 1792 + 8
                     == 84281096


https://ip2c.org/s
or
https://ip2c.org/self
or
https://ip2c.org/?self
|
+ processes caller's IP
+ faster than ?dec= option but limited to one purpose - give info about yourself


Caution
Some clients (e.g. ASP) may have issues while trying to open a file over HTTP.
In that case a slash / preceding ?ip= is obligatory.
==== Possible outputs: ===========================================================

You can use http or https.

0;;;WRONG INPUT
|
+ your request has not been processed due to invalid syntax
    |
    + e.g. bad IPv4 like 300.400.abc.256
    + e.g. bad decimal like 2a3b4c or bigger than MAX_INT


1;CD;COD;COUNTRY
|
+ contains two-letter (ISO 3166) and three-letter country codes, and a full country name
+ country name may be multi-word and contain spaces
+ e.g. we take your IP:
    |
    + URL looks like this:  https://ip2c.org/128.134.3.161
    |                       or
    |                       https://ip2c.org/?ip=128.134.3.161
    |
    + resulting string is:  1;KR;KOR;Korea Republic of


2;;;UNKNOWN
|
+ given ip/dec not found in database or not yet physically assigned to any country


The first digit indicates status so you don't have to always parse the whole string.
Output is always semicolon delimited text/plain - you can pass it to any type of application.


댓글()

[Google Map] Places search box 구글 자동완성을 이용한 위경도 값 가져오기

Open API/Google|2018. 7. 4. 15:28
반응형

구글맵 위치정보를 활용한 

자동완성 기능을 적용시키는 샘플



구글의 정보는 정말 말로 할수없을 만큼 방대합니다.


그 중에서 맵데이터는 정말 놀라운데요.


기존에 장소(정확히는 도시별)별 위경도 값을 직접 데이터관리하던 부분을


구글 장소 검색 ( Places Search Box ) 기능으로 대체하게 되었습니다.


잘 구축된 API를 잘 가져다 쓰면 되기 때문에 참 편하죠.


자동완성의 반응속도도 빠르고 나름 직접 관리하는 것보다 정확하기 때문에 


여러모로 유용할것같습니다.


실제로 구현 하는 경우에는 가장 하단에 Js 참조할때 key 값을 입력해야합니다.


https://maps.googleapis.com/maps/api/js?key=여기에키값입력&libraries=places&callback=initAutocomplete

가져온 데이터에서 위경도 값을 읽어오는 부분은 
 

// place 에서 위경도 값을 읽어올 수 있음. 


▲  이라고 주석이 달린 부분을 참고하시면 될것같습니다.








◎ 실제로 구글 API의 Response값을 체크해서 데이터를 확인해보겠습니다. ( 크롬기준 )




1. 샘플 페이지를 열어서 F12를 눌러 개발자 도구를 실행하고 Network 탭으로 이동

그리고 키워드 검색을 통해 자동완성목록이 보여지는것을 확인.

그와 동시에 AutocompletionService.GetQueryPredictions 페이지를 호출하여 값을 가져옴.


(아래 이미지는 클릭하면 커집니다)




2. 목록 중 하나를 선택 했을 때 PlaceService.GetPlaceDetails 페이지를 호출하여 상세 정보를 가져옴.


(아래 이미지는 클릭하면 커집니다)



3. 해당 호출에 대한 Request


(아래 이미지는 클릭하면 커집니다)



4. 해당 호출에 대한 Response 데이터 , 이렇게 확인이 가능합니다.

실제로 Respons되는 데이터의 항목이 다양한데 이 또한 필요에 따라 활용이 가능할것같습니다.


(아래 이미지는 클릭하면 커집니다)





아래 코드의 99%는 


https://developers.google.com/maps/documentation/javascript/examples/places-searchbox


에서도 확인 하실 수 있습니다.



<!DOCTYPE html>
<html>

<head>
	<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
	<meta charset="utf-8">
	<title>Places Searchbox</title>
	<style>
		/* Always set the map height explicitly to define the size of the div
       * element that contains the map. */

		#map {
			height: 100%;
		}

		/* Optional: Makes the sample page fill the window. */

		html,
		body {
			height: 100%;
			margin: 0;
			padding: 0;
		}

		#description {
			font-family: Roboto;
			font-size: 15px;
			font-weight: 300;
		}

		#infowindow-content .title {
			font-weight: bold;
		}

		#infowindow-content {
			display: none;
		}

		#map #infowindow-content {
			display: inline;
		}

		.pac-card {
			margin: 10px 10px 0 0;
			border-radius: 2px 0 0 2px;
			box-sizing: border-box;
			-moz-box-sizing: border-box;
			outline: none;
			box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
			background-color: #fff;
			font-family: Roboto;
		}

		#pac-container {
			padding-bottom: 12px;
			margin-right: 12px;
		}

		.pac-controls {
			display: inline-block;
			padding: 5px 11px;
		}

		.pac-controls label {
			font-family: Roboto;
			font-size: 13px;
			font-weight: 300;
		}

		#pac-input {
			background-color: #fff;
			font-family: Roboto;
			font-size: 15px;
			font-weight: 300;
			margin-left: 12px;
			padding: 0 11px 0 13px;
			text-overflow: ellipsis;
			width: 400px;
		}

		#pac-input:focus {
			border-color: #4d90fe;
		}

		#title {
			color: #fff;
			background-color: #4d90fe;
			font-size: 25px;
			font-weight: 500;
			padding: 6px 12px;
		}

		#target {
			width: 345px;
		}
	</style>
</head>

<body> <input id="pac-input" class="controls" type="text" placeholder="Search Box">
	<div id="map"></div>
	<script>
		// This example adds a search box to a map, using the Google Place Autocomplete
		// feature. People can enter geographical searches. The search box will return a
		// pick list containing a mix of places and predicted search terms.
		// This example requires the Places library. Include the libraries=places
		// parameter when you first load the API. For example:
		// <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places">
		function initAutocomplete() {
			var map = new google.maps.Map(document.getElementById('map'), {
				center: {
					lat: -33.8688,
					lng: 151.2195
				},
				zoom: 13,
				mapTypeId: 'roadmap'
			});
			// Create the search box and link it to the UI element.
			var input = document.getElementById('pac-input');
			var searchBox = new google.maps.places.SearchBox(input);
			map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
			// Bias the SearchBox results towards current map's viewport.
			map.addListener('bounds_changed', function() {
				searchBox.setBounds(map.getBounds());
			});
			var markers = [];
			// Listen for the event fired when the user selects a prediction and retrieve
			// more details for that place.
			searchBox.addListener('places_changed', function() {
				var places = searchBox.getPlaces();
				if (places.length == 0) {
					return;
				}
				// Clear out the old markers.
				markers.forEach(function(marker) {
					marker.setMap(null);
				});
				markers = [];
				// For each place, get the icon, name and location.
				var bounds = new google.maps.LatLngBounds();
				places.forEach(function(place) {
					if (!place.geometry) {
						console.log("Returned place contains no geometry");
						return;
					}

                                        // place 에서 위경도 값을 읽어올 수 있음. 
					console.log(place.geometry.location.lat());
					console.log(place.geometry.location.lng());

					var icon = {
						url: place.icon,
						size: new google.maps.Size(71, 71),
						origin: new google.maps.Point(0, 0),
						anchor: new google.maps.Point(17, 34),
						scaledSize: new google.maps.Size(25, 25)
					};
					// Create a marker for each place.
					markers.push(new google.maps.Marker({
						map: map,
						icon: icon,
						title: place.name,
						position: place.geometry.location
					}));
					if (place.geometry.viewport) {
						// Only geocodes have viewport.
						bounds.union(place.geometry.viewport);
					} else {
						bounds.extend(place.geometry.location);
					}
				});
				map.fitBounds(bounds);
			});
		}
	</script>
	<script src="https://maps.googleapis.com/maps/api/js?key=&libraries=places&callback=initAutocomplete" async defer></script>
</body>

</html>


댓글()