-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapi.php
41 lines (32 loc) · 1.01 KB
/
api.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
<?php
include_once "header.php";
header('Content-type: application/json');
$_escape = function ($str){
return preg_replace("!([\b\t\n\r\f\"\\'])!", "\\\\\\1", $str);
};
$marker_id = 0;
$places = mysql_query("SELECT * FROM places WHERE approved='1' ORDER BY name");
$places_total = mysql_num_rows($places);
echo '{ "type": "FeatureCollection", "features": [';
while($place = mysql_fetch_assoc($places)) {
$newplace = Array( );
$newplace["type"] = "Feature";
$newplace["properties"] = Array(
"name" => $_escape( $place[name] ),
"description" => $_escape( $place[description] ),
"uri" => $_escape( $place[uri] ),
"address" => $_escape( $place[address] ),
"type" => $_escape( $place[type] )
);
$newplace["geometry"] = Array(
"type" => "Point",
"coordinates" => Array( $place[lng] * 1.0, $place[lat] * 1.0 )
);
if( $marker_id > 0 ){
echo ',';
}
echo json_encode( $newplace );
$marker_id++;
}
echo '] }';
?>