-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstep3_mapapi.php
More file actions
154 lines (137 loc) · 4.76 KB
/
step3_mapapi.php
File metadata and controls
154 lines (137 loc) · 4.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
/*
STEP3
다음맵 API를 사용하는 에제입니다. SETP2 블로그 api와 연결되서 진행됩니다.
- http://dna.daum.net/myapi 에 접속하셔서 지도 apikey를 발급받으세요.
*/
//서버페이지로 블로그 오픈API 사용
$apikey = 'a72a4a6edc53aba79886a8ef1ccbb782dda6e6b3';
$request = 'http://apis.daum.net/search/blog?apikey='.$apikey.'&q='.urlencode('bnb');
//데이터 얻기(xml)
$response = file_get_contents($request);
if ($response === false) {
die('Request failed');
}
//파싱
$phpobject = simplexml_load_string($response);
if ($phpobject === false) {
die('Parsing failed');
}
?>
<!DOCTYPE html>
<html lang="kr">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>DaumBnB 1step</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<!-- 코딩 구역 시작 -->
<!-- TODO : 코딩 시작 -->
<div class="jumbotron">
<div class="container">
<h1>Daum BnB!</h1>
<p>본사이트는 전세계 어디서나 BnB 관련 정보를 찾는 사이트입니다.</p>
</div>
</div>
<div class="container">
<!-- Example row of columns -->
<div class="row">
<?php foreach($phpobject->item as $value) { //start foreache ?>
<div class="col-md-4" style="height:300px;">
<div class="panel panel-warning">
<div class="panel-heading">
<h3 class="panel-title"><?php echo "제목: ".$value->title; ?></h3>
</div>
<div class="panel-body">
<?php echo "내용: ".$value->description; ?>
<p><a class="btn btn-default" href="<?php echo $value->link; ?>" role="button" target="_blank">View details »</a></p>
</div>
</div>
</div>
<?php } //end foreach ?>
<div class="clear" style="clear:both" />
<div class="col-sm-4">
<div class="list-group" id="bnblist">
</div>
</div>
</div>
<!-- 지도가 표시되는 구역입니다. -->
<div id="map" style="width:600px;height:600px;"></div>
<!-- 코딩 구역 끝 -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://apis.daum.net/maps/maps3.js?apikey=6b96607bfaa8f55d7b6223445d64a60ecc825189" charset="utf-8"></script>
<script type="text/javascript">
var map;
//페이지 로드시 실행
$( document ).ready(function() {
loadData();
});
// data/bnblist.json데이터 저장
var bnbListData;
function loadData()
{
$.getJSON( "/data/bnblist.json", function( data ) {
bnbListData = data;
drawList();
//지도그리기(지도API 강의)
drawMap();
});
}
//리스트 출력
function drawList()
{
$.each(bnbListData.list, function(i, item) {
$itemTag = createBnbItem(item.lat,item.lng,item.url, item.name, item.desc);
$itemTag.appendTo("#bnblist");
});
}
//리스트 태그 생성
function createBnbItem(lat, lng, url, name, desc)
{
var aTag = $('<a onclick="return onBnbItem('+lat+','+lng+')" href="'+url+'" class="list-group-item" target="_blank">');
var h4Tag = $('<h4 class="list-group-item-heading">');
h4Tag.text(name);
h4Tag.appendTo(aTag);
var pTag = $('<p class="list-group-item-text">');
pTag.text(desc);
pTag.appendTo(aTag);
return aTag;
}
//리스트 클릭
function onBnbItem(lat,lng)
{
map.panTo(new daum.maps.LatLng(lat, lng));
return false;
}
//지도 그리기
function drawMap() {
map = new daum.maps.Map(document.getElementById('map'), {
center: new daum.maps.LatLng(37.537123, 127.005523),
level: 4
});
var icon = new daum.maps.MarkerImage(
'http://localimg.daum-img.net/localimages/07/2009/map/icon/blog_icon01_on.png',
new daum.maps.Size(31, 34),
new daum.maps.Point(16,34),
"poly",
"1,20,1,9,5,2,10,0,21,0,27,3,30,9,30,20,17,33,14,33"
);
$.each(bnbListData.list, function(i, item) {
var latlan = new daum.maps.LatLng(item.lat,item.lng);
new daum.maps.Marker({
position: latlan,
image: icon
}).setMap(map);
});
}
</script>
</body>
</html>