구글맵(Google Maps JavaScript API v3) 주소로 검색하기 - Geocoding
아래 $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>
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개
10년 전
$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사용이 가능해야합니다
삭제하시고
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사용이 가능해야합니다
10년 전
옵션님 감사합니다. ^^
9년 전
좋은 팁 감사합니다
hoinV
9년 전
적용해보려고 합니다. ^^ 감사합니다.
게시판 목록
그누보드5 팁자료실
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 공지 | 3년 전 | 4429 | ||
| 444 | 10년 전 | 9068 | ||
| 443 | 10년 전 | 7057 | ||
| 442 |
|
10년 전 | 9549 | |
| 441 | 10년 전 | 9009 | ||
| 440 |
블랙앤화이트
|
10년 전 | 10106 | |
| 439 | 10년 전 | 8895 | ||
| 438 | 10년 전 | 10205 | ||
| 437 | 10년 전 | 9627 | ||
| 436 | 10년 전 | 10012 | ||
| 435 | 10년 전 | 6344 | ||
| 434 | 10년 전 | 13713 | ||
| 433 | 10년 전 | 8295 | ||
| 432 | 10년 전 | 7009 | ||
| 431 | 10년 전 | 20667 | ||
| 430 | 10년 전 | 11399 | ||
| 429 | 10년 전 | 4583 | ||
| 428 | 10년 전 | 10836 | ||
| 427 | 10년 전 | 9708 | ||
| 426 | 10년 전 | 10272 | ||
| 425 | 10년 전 | 19821 | ||
| 424 | 10년 전 | 10974 | ||
| 423 | 10년 전 | 6595 | ||
| 422 |
untitled
|
10년 전 | 11676 | |
| 421 | 10년 전 | 23219 | ||
| 420 | 10년 전 | 15551 | ||
| 419 |
wkpark
|
10년 전 | 15117 | |
| 418 | 10년 전 | 11394 | ||
| 417 | 10년 전 | 10703 | ||
| 416 |
|
10년 전 | 13353 | |
| 415 | 10년 전 | 8832 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기