-
Notifications
You must be signed in to change notification settings - Fork 0
/
getmapdata-bylocation.php
59 lines (54 loc) · 1.73 KB
/
getmapdata-bylocation.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
<?php
header('Content-Type: application/json');
include('common.php');
$config = include('config.php');
$bingKey = $config['bingAPIKey'];
$client_key = $config['clientids'];
$mapType = $config['defaultMapType'];
$mapSize = $config['defaultMapSize'];
$zoomLevel = $config['defaultZoomLevel'];
//Check authentication
$request_headers = get_request_headers();
if ($client_key != '') { //If configuration includes both client key values, enforce them
if (!array_key_exists('Client-Id', $request_headers)) {
echo "{\"status\": \"error\", \"msg\": \"ERROR: Not authorized\"}";
die;
} else {
$request_key = $request_headers['Client-Id'];
if (!in_array($request_key, $client_key)) {
echo "{\"status\": \"error\", \"msg\": \"ERROR: No authorized user.\"}";
echo $request_key;
echo $client_key;
die;
}
}
}
//Figure the query
$mapType = "Road";
$zoomLevel = 10;
if (isset($_GET['q'])) {
$the_query = $_GET['q'];
if (isset($_GET["mapType"]))
$mapType = $_GET["mapType"];
if (isset($_GET["mapSize"]))
$mapSize = $_GET["mapSize"];
$pushPin = ";122";
if (isset($_GET["pushPin"]))
$pushPin = $_GET["pushPin"];
if (isset($_GET["zoomLevel"]))
$zoomLevel = $_GET["zoomLevel"];
if (isset($_GET["key"]) && $_GET["key"] != "")
$bingKey = $_GET["key"];
} else {
$the_query = $_SERVER['QUERY_STRING'];
}
//Get results
$mapData = getDataForLocation($the_query, $mapType, $mapSize, $pushPin, $zoomLevel, $bingKey);
if (!isset($mapData) || $mapData == "") {
echo "{\"status\": \"error\", \"msg\": \"ERROR: No usable response from Map service. Query may have been malformed, or API quota may have been exceeded.\"}";
die;
}
//Collect and show the results
header('Content-Type: application/json');
print_r (json_encode($mapData));
?>