@dhruvdutt/

Appbase.io - PHP - GeoDistance

PHP (Legacy)

Query rooms available within a certain distance from a specific (lat,lon) location.

fork
loading

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.04686816314771303","path":"main.php","file":{"path":"main.php","content":{"asEncoding":{"base64":"JGN1cmwgPSBjdXJsX2luaXQoKTsKCmN1cmxfc2V0b3B0X2FycmF5KCRjdXJsLCBhcnJheSgKICBDVVJMT1BUX1VSTCA9PiAiaHR0cHM6Ly9zY2Fsci5hcGkuYXBwYmFzZS5pby9ob3VzaW5nLWRlbW8vbGlzdGluZy9fc2VhcmNoIiwKICBDVVJMT1BUX1JFVFVSTlRSQU5TRkVSID0+IHRydWUsCiAgQ1VSTE9QVF9FTkNPRElORyA9PiAiIiwKICBDVVJMT1BUX01BWFJFRElSUyA9PiAxMCwKICBDVVJMT1BUX1RJTUVPVVQgPT4gMzAsCiAgQ1VSTE9QVF9IVFRQX1ZFUlNJT04gPT4gQ1VSTF9IVFRQX1ZFUlNJT05fMV8xLAogIENVUkxPUFRfQ1VTVE9NUkVRVUVTVCA9PiAiUE9TVCIsCiAgQ1VSTE9QVF9QT1NURklFTERTID0+IGpzb25fZW5jb2RlKGFycmF5KAogICAgInF1ZXJ5IiA9PiBhcnJheSgKICAgICAgImdlb19kaXN0YW5jZSIgPT4gYXJyYXkoCiAgICAgICAgImRpc3RhbmNlIiA9PiAiNW1pIiwKICAgICAgICAibG9jYXRpb24iID0+IGFycmF5KAogICAgICAgICAgImxhdCIgPT4gNDcuNTksCiAgICAgICAgICAibG9uIiA9PiAtMTIyLjI5CiAgICAgICAgKQogICAgICApICAgICAKICAgICkKICApKSwKICBDVVJMT1BUX0hUVFBIRUFERVIgPT4gYXJyYXkoCiAgICAiQXV0aG9yaXphdGlvbjogQmFzaWMgV1c1RFoxWjNiM3BXT21VNVpXTTFZMkl3TFRVNFpEZ3ROR0ppTUMxaVlXUmpMV0ZqWVdZM01qWTJOakZtTVE9PSIsCiAgICAiQ29udGVudC1UeXBlOiBhcHBsaWNhdGlvbi9qc29uIgogICksCikpOwoKJHJlc3BvbnNlID0gY3VybF9leGVjKCRjdXJsKTsKJGVyciA9IGN1cmxfZXJyb3IoJGN1cmwpOwoKY3VybF9jbG9zZSgkY3VybCk7CgppZiAoJGVycikgewogIGVjaG8gImNVUkwgRXJyb3IgIzoiIC4gJGVycjsKfSBlbHNlIHsKICAkanNvbiA9IGpzb25fZGVjb2RlKCRyZXNwb25zZSwgdHJ1ZSk7CiAgcHJpbnRfcigiQHNlYXJjaCBoaXRzOiAiKTsKICBwcmludF9yKCRqc29uWydoaXRzJ11bJ2hpdHMnXSk7Cn0="},"asBuffer":null},"loaded":true}}
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
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://scalr.api.appbase.io/housing-demo/listing/_search",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode(array(
    "query" => array(
      "geo_distance" => array(
        "distance" => "5mi",
        "location" => array(
          "lat" => 47.59,
          "lon" => -122.29
        )
      )     
    )
  )),
  CURLOPT_HTTPHEADER => array(
    "Authorization: Basic WW5DZ1Z3b3pWOmU5ZWM1Y2IwLTU4ZDgtNGJiMC1iYWRjLWFjYWY3MjY2NjFmMQ==",
    "Content-Type: application/json"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  $json = json_decode($response, true);
  print_r("@search hits: ");
  print_r($json['hits']['hits']);
}
PHP 7.0.8 (Legacy: use the following for new features: Command-line PHP: https://repl.it/languages/php_cli PHP Web Server: https://repl.it/languages/php7