중국에서 Google map 실행이 안되는 경우 해결 방법

Open API/Google|2018. 10. 23. 14:42
반응형

중국내에서 Google map 실행이 안되는 경우 해결 방법


원인은 https 접속이 안되기 때문이고 

이 문제는 Google map FAQ에서 해결 방법을 제시해주고 있습니다.



아래 내용은 Google Map FAQ의 일부 발췌한 내용입니다.


Google Maps Platform products are served within China from the domain maps.google.cn. This domain does not support https. When making requests to Google Maps Platform products from China, please replace https://maps.googleapis.com with http://maps.google.cn.



중국에서 https://maps.googleapis.com 접속이 정상적으로 이뤄지지 않기 때문에


http 통신을 해야하고 중국내에서 이용할 수있는 도메인은 http://maps.google.cn 


아래와 같이 Google Map API javascript 파일 참조시에 도메인을 변경해줍니다.



<script src="http://maps.google.cn/maps/api/js?key=YOUR_API_KEY"
type="text/javascript">
</script>



내용이 변경될 수 있기 때문에 Google Map FAQ 링크를 함께 남깁니다.


https://developers.google.com/maps/faq#china_ws_access

댓글()

PHP + Google Translate API 연동하기

Progmming/PHP|2018. 5. 4. 13:19
반응형

PHP + Google Translate API 연동하기



Google translate document site

https://cloud.google.com/translate/docs/?hl=ko



Google 에서 제공되는 샘플 소스

https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/translate


 

하지만 그냥 최소한의 코딩으로 처리를 하고자 했기 때문에..


php 함수를하나 만듬.


function translate($content) { $handle = curl_init(); curl_setopt($handle, CURLOPT_URL,'https://www.googleapis.com/language/translate/v2'); curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1); curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false); $data = array('key' => "API Key", 'q' => $content, 'source' => "ko", 'target' => "en"); curl_setopt($handle, CURLOPT_POSTFIELDS, preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', http_build_query($data))); curl_setopt($handle,CURLOPT_HTTPHEADER,array('X-HTTP-Method-Override: GET')); $response = curl_exec($handle); $responseDecoded = json_decode($response, true); $responseCode = curl_getinfo($handle, CURLINFO_HTTP_CODE); curl_close($handle); return $responseDecoded['data']['translations'][0]['translatedText']; }


사용을 위해 신용카드 등록이 필요하지만 처음 등록 할 경우 300달러가 제공되니 참고해주세요.

댓글()

[Google API] 구글맵 v3 infoBox

Open API/Google|2016. 12. 14. 23:13
반응형



구글맵 infoWindow 만으로는 html 사용에 제약이 많습니다.

디자인 소스 적용이 어렵기 때문입니다.


해결을 위해 플러그인이 제공되고 있습니다.

그 이름 " infoBox" !!


좀더 자유롭게 디자인 소스를 입힐 수 있는데요.


사용하기 위해서는 infobox.js 를 추가해야 합니다.

JS : 다운로드



샘플 코드 :   http://www.uhoon.co.kr/test/6502.html


** 기본 infoWindow에서는 불가능 했던 각종 옵션들이 무궁무진합니다. ** 


API Reference :  

http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/reference.html


<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?v=3&sensor=false"></script>
<script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/src/infobox.js"></script>
<script type="text/javascript">
	function initialize() {
		var secheltLoc = new google.maps.LatLng(49.47216, -123.76307);

		var myMapOptions = {
			 zoom: 15
			,center: secheltLoc
			,mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		var theMap = new google.maps.Map(document.getElementById("map_canvas"), myMapOptions);


		var marker = new google.maps.Marker({
			map: theMap,
			draggable: true,
			position: new google.maps.LatLng(49.47216, -123.76307),
			visible: true
		});

		var boxText = document.createElement("div");
		boxText.style.cssText = "border: 1px solid black; margin-top: 8px; background: yellow; padding: 5px;";
		boxText.innerHTML = "City Hall, Sechelt<br>British Columbia<br>Canada";

		var myOptions = {
			 content: boxText
			,disableAutoPan: false
			,maxWidth: 0
			,pixelOffset: new google.maps.Size(-140, 0)
			,zIndex: null
			,boxStyle: { 
			  background: "url('tipbox.gif') no-repeat"
			  ,opacity: 0.75
			  ,width: "280px"
			 }
			,closeBoxMargin: "10px 2px 2px 2px"
			,closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif"
			,infoBoxClearance: new google.maps.Size(1, 1)
			,isHidden: false
			,pane: "floatPane"
			,enableEventPropagation: false
		};

		google.maps.event.addListener(marker, "click", function (e) {
			ib.open(theMap, this);
		});

		var ib = new InfoBox(myOptions);

		ib.open(theMap, marker);
	}
</script>

<title>Creating and Using an InfoBox</title>
</head>
<body onload="initialize()">
	<div id="map_canvas" style="width: 100%; height: 400px"></div>
	<p>
	This example shows the "traditional" use of an InfoBox as a replacement for an InfoWindow.
</body>

</html>


댓글()