SHARE
TWEET

Untitled

a guest May 19th, 2017 42 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.     //Ontvang alle binnenkomende variabelen (deze kan je uitbreiden)
  3.     $requiredFields = array("userId", "developerId", "developerHash", "timestamp", "layerName", "lat", "lon", "accuracy", "radius");
  4.     //stop ze in variabelen zodat je ze later kan gebruiken
  5.     foreach ($requiredFields as $field) {
  6.         ${$field} = $_GET[$field];
  7.     }
  8.  
  9.     //Maak de SQL query, Dit is de vraag die je gaat stellen aan de database
  10.     $sql = "select id, type, title, lat, lon, line2, line3, line4, attribution, imageURL, action
  11.    , 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
  12.    FROM POI
  13.    HAVING distance < (" . addslashes($radius) . " + " . addslashes($accuracy) . ")
  14.    ORDER BY distance ASC
  15.    LIMIT 0 , 50";
  16.  
  17.     //Vertel je script waar de database server staat en hoe hij / zij binnen mag komen
  18.     $con = mysql_connect("localhost","schoon2i","VfjY7pyz");
  19.     if (!$con) {
  20.           die('Could not connect: ' . mysql_error());
  21.       }
  22.     // Vertel je script in welke database hij / zij moet zoeken
  23.     mysql_select_db("stu_schoon2i", $con);
  24.    
  25.     // Haal de resultaten uit je database tabel staan op
  26.     $result = mysql_query($sql);
  27.  
  28.     // begin met het formuleren van een antwoord
  29.     $response = array();
  30.     $response["morePages"] = $morePages;
  31.     $response["nextPageKey"] = (string)$nextPageKey;
  32.     $response["layer"] = $_REQUEST["layerName"];
  33.     $response["errorCode"] = 0;
  34.     $response["errorString"] = "ok";
  35.     $response["hotspots"] = array();
  36.  
  37.     while($row = mysql_fetch_array($result))
  38.       {
  39.           // hou een teller bij
  40.         $i = count($response["hotspots"]);
  41.        
  42.         // Op dit punt kan je zien welke database velden je aan welke JSON hangt
  43.             $poi = array();
  44.             $actions = array();
  45.            
  46.             $poi["id"] = $row["id"];
  47.             $poi["title"] = $row["title"];
  48.             $poi["type"] = $row["type"];
  49.             $poi["lat"] = $row["lat"];
  50.             $poi["lon"] = $row["lon"];
  51.             $poi["line2"] = $row["line2"];
  52.             $poi["line3"] = $row["line3"];
  53.             $poi["line4"] = $row["line4"];
  54.             $poi["attribution"] = $row["attribution"];
  55.             $poi["imageURL"] = $row["imageURL"];
  56.             $poi["distance"] = $row["distance"];
  57.             $poi["actions"] = $actions;
  58.            
  59.             $response["hotspots"][$i] = $poi;
  60.            
  61.             // upscale coordinate values and truncate to int because of inconsistencies in Layar API
  62.             // (requests use floats, responses use integers?)
  63.             $response["hotspots"][$i]["lat"] = (int)($response["hotspots"][$i]["lat"] * 1000000);
  64.             $response["hotspots"][$i]["lon"] = (int)($response["hotspots"][$i]["lon"] * 1000000);
  65.             // fix some types that are not strings
  66.             $response["hotspots"][$i]["type"] = (int)$response["hotspots"][$i]["type"];
  67.             $response["hotspots"][$i]["distance"] = (float)$response["hotspots"][$i]["distance"];
  68.     }  
  69.  
  70.     // Sluit de verbinding naar de database
  71.     mysql_close($con);
  72.  
  73.     /* Set the proper content type */
  74.     //header("Content-Type: application/json");
  75.     // Vertaal de Arrays naar JSON
  76.     printf("%s", json_encode($response));
  77. ?>
RAW Paste Data
Top