테스트 사이트 - 개발 중인 베타 버전입니다

구글맵(Google Maps JavaScript API v3) 주소로 검색하기 - Geocoding

· 10년 전 · 10604 · 4
아래 $address 와 $address_title 에 게시판에서 저장할때 추가필드에 주소를 저장시킨후 그것을 연결하면 게시판에서 실시간으로 주소를 추출해서 보이도록 스킨을 만드는것도 얼마든지 가능합니다.

php.ini 의 설정값중 allow_url_fopen = On 이어야만 $lat , $lng 가 추출된다는 것이 문제일수 있습니다.
호스팅사에 그것이 설정을 못변경해준다고 하는 경우에는 무슨 다른 방법이 있을듯한데...
그것을 아시는분 댓글 부탁드립니다.


<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<?php
$address = "서울시 구로구 디지털로 242";
$address_title = "해피정닷컴;

$xml = simplexml_load_file("http://maps.google.com/maps/api/geocode/xml?address=".urlencode($address)."&language=ko&sensor=false");
$lat = $xml->result->geometry->location->lat;
$lng = $xml->result->geometry->location->lng;

// php.ini 설정중 allow_url_fopen = On 확인 / Off 이면 추출안됨
//echo "lat = ". $lat ."<br>";
//echo "lng = ". $lng ."<br>";
?>
<!-- GoogoleMap Asynchronously Loading the API ********************************************* -->
<script type="text/javascript">
function initialize() {
var mapLocation = new google.maps.LatLng('<?php echo $lat; ?>', '<?php echo $lng; ?>'); // 지도에서 가운데로 위치할 위도와 경도
var markLocation = new google.maps.LatLng('<?php echo $lat; ?>', '<?php echo $lng; ?>'); // 마커가 위치할 위도와 경도

var mapOptions = {
center: mapLocation, // 지도에서 가운데로 위치할 위도와 경도(변수)
zoom: 16, // 지도를 띄웠을 때의 줌 크기
mapTypeId: google.maps.MapTypeId.ROADMAP
};

var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions); // div의 id과 값이 같아야 함. "map-canvas"

var size_x = 40; // 마커로 사용할 이미지의 가로 크기
var size_y = 40; // 마커로 사용할 이미지의 세로 크기

// 마커로 사용할 이미지 주소
var image = new google.maps.MarkerImage( '',
new google.maps.Size(size_x, size_y),
'',
'',
new google.maps.Size(size_x, size_y));

var marker;
marker = new google.maps.Marker({
position: markLocation, // 마커가 위치할 위도와 경도(변수)
map: map,
icon: image, // 마커로 사용할 이미지(변수)
// info: '말풍선 안에 들어갈 내용',
title: '<?php echo $address_title; ?>' // 마커에 마우스 포인트를 갖다댔을 때 뜨는 타이틀
});

var content = "<?php echo $address_title; ?>"; // 말풍선 안에 들어갈 내용

// 마커를 클릭했을 때의 이벤트. 말풍선 뿅~
var infowindow = new google.maps.InfoWindow({ content: content});

google.maps.event.addListener(marker, "click", function() {
infowindow.open(map,marker);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<div id="map-canvas" style="width: 100%; height: 313px" title="<?php echo $address_title; ?>"></div>

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기

댓글 4개

$xml = simplexml_load_file("http://maps.google.com/maps/api/geocode/xml?address=".urlencode($address)."&language=ko&sensor=false");
삭제하시고


if(ini_get('allow_url_fopen')) {
$xml = simpleXML_load_file(http://maps.google.com/maps/api/geocode/xml?address=".urlencode($address)."&language=ko&sensor=false);
}else{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$xml_raw = curl_exec($ch);
$xml = simplexml_load_string($xml_raw);
}
추가하시면 됩니다 단 curl사용이 가능해야합니다
옵션님 감사합니다. ^^
9년 전
좋은 팁 감사합니다
적용해보려고 합니다. ^^ 감사합니다.

게시글 목록

번호 제목
2410
2401
2395
2387
2385
2377
2374
2372
2368
2367
2366
2364
2354
2353
2352
2349
2333
2329
2327
2304
2298
2297
2295
2288
2282
2279
2278
2276
2273
2268