-
Notifications
You must be signed in to change notification settings - Fork 3
/
placemarks.php
178 lines (153 loc) · 4.88 KB
/
placemarks.php
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
/*
* XML(JSON) generator for jQuery GoogleMaps Plugin
*
* Copyright (c) 2011 TORU KOKUBUN (http://d-s-b.jp/)
* Licensed under MIT Lisence:
* http://www.opensource.org/licenses/mit-license.php
* http://sourceforge.jp/projects/opensource/wiki/licenses%2FMIT_license
*
* Last Modified: 2011-07-04
* version: 1.00
*
*/
/* ---------------------------------------------------------
init Placemarks Array
------------------------------------------------------------ */
$format = NULL;
$callback = NULL;
$placemarks = array();
// set Placemark Properties
array_push($placemarks,
//マーカーに関する情報・ここから
array(
'name' => '郡山市役所',
'description' => '
<img src="http://mw2.google.com/mw-panoramio/photos/thumbnail/25589455.jpg">
〒963-8024<br>
福島県郡山市朝日1丁目23−7<br>
024-924-2491<br>
<a href="http://www.city.koriyama.fukushima.jp/">city.koriyama.fukushima.jp</a>',
'url' => 'http://www.city.koriyama.fukushima.jp/',
'lookat' => array(
'latitude' => '37.400529',
'longitude' => '140.359743'
),
'icon' => 'orangeDot'
),
//マーカーに関する情報・ここまで(最後のマーカーのみ、直前のカンマは不要。)
array(
'name' => '郡山市民文化センター',
'description' => '
<img src="http://mw2.google.com/mw-panoramio/photos/thumbnail/24671550.jpg">
〒963-8878<br>
福島県郡山市堤下町1−2<br>
024-934-2288<br>
<a href="http://bunka-manabi.or.jp/">bunka-manabi.or.jp</a>',
'lookat' => array(
'latitude' => '37.392745',
'longitude' => '140.378156'
),
'icon' => 'blueDot'
),
array(
'name' => '郡山市中央図書館',
'description' => '
<img src="http://mw2.google.com/mw-panoramio/photos/thumbnail/34055024.jpg">
〒963-8876<br>
福島県郡山市麓山1丁目5−25<br>
024-923-6601<br>
<a href="http://www.city.koriyama.fukushima.jp/">city.koriyama.fukushima.jp</a>',
'lookat' => array(
'latitude' => '37.393830',
'longitude' => '140.374302'
),
'icon' => 'greenDot'
)
);
get_request_parameters();
output_http_response();
/* ---------------------------------------------------------
Function
------------------------------------------------------------ */
// Get Request Parameters
function get_request_parameters() {
global $format, $callback;
if (isset($_REQUEST['format'])) {
$format = $_REQUEST['format'];
}
if (isset($_REQUEST['callback'])) {
$callback = $_REQUEST['callback'];
}
}
// Output Http-Response
function output_http_response() {
global $format, $callback;
mb_http_output('UTF-8');
if ($format == 'xml') {
header('Content-type: text/xml');
echo create_xml();
} else if ($format == 'json') {
header('Content-type: application/json; charset=utf-8');
header('Last-Modified: '.gmdate( 'D, d M Y H:i:s' ).' GMT');
header('pragma: no-cache');
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Tue, 31 Mar 1981 05:00:00 GMT");
if($callback) {
echo $callback . '(' . create_json() . ');';
}else {
echo create_json();
}
} else {
header('Content-type: text/xml');
echo create_error();
}
}
/* ---------------------------------------------------------
Generate Response Data
------------------------------------------------------------ */
// Response XML
function create_xml() {
global $placemarks;
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->formatOutput = true;
$placemarks_node = $dom->createElement('Placemarks');
$dom->appendChild($placemarks_node);
foreach ($placemarks as $val) {
$placemark_node = $placemarks_node->appendChild($dom->createElement('Placemark'));
foreach ($val as $k => $v) {
if($k == 'lookat'){ $k = 'LookAt'; }
$node = $placemark_node->appendChild($dom->createElement($k));
if($k == 'description'){
$node->appendChild($dom->createCDATASection($v));
} else if($k == 'LookAt'){
foreach ($v as $label => $point) {
$sub_node = $node->appendChild($dom->createElement($label));
$sub_node->appendChild($dom->createTextNode($point));
}
} else {
$node->appendChild($dom->createTextNode($v));
}
}
}
return $dom->saveXML();
}
// Response JSON
function create_json() {
global $placemarks;
$placemark = array();
$num = 0;
foreach ($placemarks as $v) {
$placemark['placemarks'][$num] = $v;
$num ++;
}
return json_encode($placemark);
}
// Response ERROR
function create_error() {
$data = '<result></result>';
$sxe = new SimpleXMLElement($data);
$sxe->addChild('error', 'Sorry. This request is not supported format.');
return $sxe->asXML();
}
?>