Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Ontvang alle binnenkomende variabelen (deze kan je uitbreiden)
- $requiredFields = array("userId", "developerId", "developerHash", "timestamp", "layerName", "lat", "lon", "accuracy", "radius");
- //stop ze in variabelen zodat je ze later kan gebruiken
- foreach ($requiredFields as $field) {
- ${$field} = $_GET[$field];
- }
- //Maak de SQL query, Dit is de vraag die je gaat stellen aan de database
- $sql = "select id, type, title, lat, lon, line2, line3, line4, attribution, imageURL, action
- , 6371010 * 2 * asin(sqrt(pow(sin((radians(" . addslashes($lat) . ") - radians(lat)) / 2), 2) + cos(radians(" . addslashes($lat) . ")) * cos(radians(lat)) * pow(sin((radians(" . addslashes($lon) . ") - radians(lon)) / 2), 2))) AS distance
- FROM POI
- HAVING distance < (" . addslashes($radius) . " + " . addslashes($accuracy) . ")
- ORDER BY distance ASC
- LIMIT 0 , 50";
- //Vertel je script waar de database server staat en hoe hij / zij binnen mag komen
- $con = mysql_connect("localhost","schoon2i","VfjY7pyz");
- if (!$con) {
- die('Could not connect: ' . mysql_error());
- }
- // Vertel je script in welke database hij / zij moet zoeken
- mysql_select_db("stu_schoon2i", $con);
- // Haal de resultaten uit je database tabel staan op
- $result = mysql_query($sql);
- // begin met het formuleren van een antwoord
- $response = array();
- $response["morePages"] = $morePages;
- $response["nextPageKey"] = (string)$nextPageKey;
- $response["layer"] = $_REQUEST["layerName"];
- $response["errorCode"] = 0;
- $response["errorString"] = "ok";
- $response["hotspots"] = array();
- while($row = mysql_fetch_array($result))
- {
- // hou een teller bij
- $i = count($response["hotspots"]);
- // Op dit punt kan je zien welke database velden je aan welke JSON hangt
- $poi = array();
- $actions = array();
- $poi["id"] = $row["id"];
- $poi["title"] = $row["title"];
- $poi["type"] = $row["type"];
- $poi["lat"] = $row["lat"];
- $poi["lon"] = $row["lon"];
- $poi["line2"] = $row["line2"];
- $poi["line3"] = $row["line3"];
- $poi["line4"] = $row["line4"];
- $poi["attribution"] = $row["attribution"];
- $poi["imageURL"] = $row["imageURL"];
- $poi["distance"] = $row["distance"];
- $poi["actions"] = $actions;
- $response["hotspots"][$i] = $poi;
- // upscale coordinate values and truncate to int because of inconsistencies in Layar API
- // (requests use floats, responses use integers?)
- $response["hotspots"][$i]["lat"] = (int)($response["hotspots"][$i]["lat"] * 1000000);
- $response["hotspots"][$i]["lon"] = (int)($response["hotspots"][$i]["lon"] * 1000000);
- // fix some types that are not strings
- $response["hotspots"][$i]["type"] = (int)$response["hotspots"][$i]["type"];
- $response["hotspots"][$i]["distance"] = (float)$response["hotspots"][$i]["distance"];
- }
- // Sluit de verbinding naar de database
- mysql_close($con);
- /* Set the proper content type */
- //header("Content-Type: application/json");
- // Vertaal de Arrays naar JSON
- printf("%s", json_encode($response));
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement