Advertisement
lmohanarun

Foursquare "Venues" demo

Oct 15th, 2015
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.00 KB | None | 0 0
  1. <!doctype html>
  2. <head>
  3. <title>Which Apple Store is the busiest? todo: lookup table of logo graphics sortable table.</title>
  4. <link rel="import" href="statcounter-include.html">
  5. <!--Start of Zopim Live Chat Script-->
  6. <script type="text/javascript">
  7. window.$zopim||(function(d,s){var z=$zopim=function(c){z._.push(c)},$=z.s=
  8. d.createElement(s),e=d.getElementsByTagName(s)[0];z.set=function(o){z.set.
  9. _.push(o)};z._=[];z.set._=[];$.async=!0;$.setAttribute("charset","utf-8");
  10. $.src="//v2.zopim.com/?3OEmwjPqSV4goKBnrct9k32AQkWeres8";z.t=+new Date;$.
  11. type="text/javascript";e.parentNode.insertBefore($,e)})(document,"script");
  12. </script>
  13. <!--End of Zopim Live Chat Script-->
  14. <script type="text/javascript" language="javascript" src="//code.jquery.com/jquery-1.11.3.min.js"></script>
  15. <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.10.9/js/jquery.dataTables.min.js"></script>
  16.  
  17. <style type="text/css">
  18. /*  Define the background color for all the ODD background rows  */
  19. #busiest tr:nth-child(odd){
  20.     background: #b8d1f3;
  21. }
  22. /*  Define the background color for all the EVEN background rows  */
  23. #busiest tr:nth-child(even){
  24.     background: #dae5f4;
  25. }
  26.  
  27. tfoot input {
  28.         width: 100%;
  29.         padding: 3px;
  30.         box-sizing: border-box;
  31.     }
  32. </style>
  33. <script type="text/javascript" class="init">
  34. $(document).ready(function() {
  35.     $('#busiest').DataTable( {
  36.         columnDefs: [ {
  37.             targets: [ 3 ],
  38.             orderData: [ 1, 0 ]
  39.         }, {
  40.             targets: [ 4 ],
  41.             orderData: [ 1, 0 ]
  42.         } ]
  43.     } );
  44. } );
  45.  
  46.     </script>
  47. </head>
  48. <body>
  49. <div name="4sqfeed" style="border:red 2px solid; width:100%;">
  50.  
  51. <?php
  52. //see geocoder.us, mygeoposition.com
  53. //-6.214239,106.80723 = Indonesia
  54. //New York: 40.755932,-73.986508
  55. $formsubm = $_REQUEST['formsubm'];
  56. //http://www.webmasterworld.com/forum88/9375.htm
  57. //http://geocoder.us/help/city_state_zip.shtml
  58. //http://geocoder.us/service/csv/geocode?zip=95472
  59. if(!isset($formsubm))
  60. {
  61.     $latlon = "40.755932,-73.986508";
  62.     $place = "Apple Store";
  63. }
  64. else
  65. {
  66.     $latlon = $_REQUEST['latlon'];
  67.     $place = $_REQUEST['placename'];
  68. }
  69.  
  70. if ($latlon =="40.755932,-73.986508") $locname="New York";
  71. if ($latlon =="42.348522,-71.082229") $locname="Boston";
  72. if ($latlon =="41.894786,-87.623949") $locname="Chicago";
  73. if ($latlon =="29.739134,-95.464410") $locname="Houston";
  74. if ($latlon =="37.785840,-122.406100") $locname="San Francisco";
  75. ?>
  76.  
  77. <h2>Which &lt;<u><?= $place; ?></u>&gt; is the busiest in &lt;<u><?= $locname; ?></u>&gt;</h2>
  78. <h4>What is it?</h4>
  79. <p align=justify>I am using the FOURSQUARE REST API/JSON based output by registering this as a REST app with Foursquare developer program. I am also using CSS, HTML5, embedded PHP in HTML,OAuth2 based flow authentication, geocoding, I am using Foursquare's v2/venues/search which can be viewed https://developer.foursquare.com/overview/venues
  80. </p>
  81. <p align=justify>
  82. Geocoding is the process of converting addresses (like "1600 Amphitheatre Parkway, Mountain View, CA") into geographic coordinates (like latitude 37.423021 and longitude -122.083739), which you can use to place markers on a map, or position the map. One could use Google Maps Geocoding API, but I am using a more simpler geocoding: Since physical place names are made by God to remain in the same latitude/longitude, I found the lat/lon of popular cities in the US such as N.Y., Boston, Chicago, Houston and San Francisco. These lat/lon are hardcoded into this simple one-page app for simplicity sake. Example, New York is always at lat/lon 40.755932,-73.986508 and wont change. The PHP form does self-submit.
  83. </p>
  84. <img src="https://ss0.4sqi.net/img/poweredByFoursquare/poweredby-full-color-bf549c16c0ab3e1b04706ab5fcb422f1.png"/>
  85. <br/>
  86. <form method="post">
  87. Place:
  88. <select name="placename">
  89. <option value="Apple Store" <?= ($place=="Apple Store") ? "SELECTED" : ""; ?>>Apple Store</option>
  90. <option value="Macys" <?= ($place=="Macys") ? "SELECTED" : ""; ?>>Macys</option>
  91. <option value="Walgreens" <?= ($place=="Walgreens") ? "SELECTED" : ""; ?>>Walgreens</option>
  92. <option value="KFC" <?= ($place=="KFC") ? "SELECTED" : ""; ?>>KFC</option>
  93. <option value="Trader Joes" <?= ($place=="Trader Joes") ? "SELECTED" : ""; ?>>Trader Joes</option>
  94. <option value="Taco Bell" <?= ($place=="Taco Bell") ? "SELECTED" : ""; ?>>Taco Bell</option>
  95. <option value="McDonalds" <?= ($place=="McDonalds") ? "SELECTED" : ""; ?>>McDonalds</option>
  96. <option value="Starbucks" <?= ($place=="Starbucks") ? "SELECTED" : ""; ?>>Starbucks</option>
  97. </select>
  98.  
  99. <select name="latlon">
  100. <option value="40.755932,-73.986508" <?= ($latlon=="40.755932,-73.986508") ? "SELECTED" : ""; ?>>New York</option>
  101. <option value="42.348522,-71.082229" <?= ($latlon=="42.348522,-71.082229") ? "SELECTED" : ""; ?>>Boston</option>
  102. <option value="41.894786,-87.623949" <?= ($latlon=="41.894786,-87.623949") ? "SELECTED" : ""; ?>>Chicago</option>
  103. <option value="29.739134,-95.464410" <?= ($latlon=="29.739134,-95.464410") ? "SELECTED" : ""; ?>>Houston</option>
  104. <option value="37.785840,-122.406100" <?= ($latlon=="37.785840,-122.406100") ? "SELECTED" : ""; ?>>San Francisco</option>
  105. </select>
  106.  
  107. <input type=hidden name="formsubm" value="1"/>
  108. <input type=submit name="submit" value="Submit">
  109. </form>
  110. <br/><br/>
  111.  
  112. checkinsCount = (total checkins ever)
  113. <br/>
  114. usersCount = (total users who have ever checked in here).
  115. <br/>
  116. hereNow = (users checked in now)
  117. <br/>
  118.  
  119. <?php
  120. $place_e = urlencode($place);
  121. $url = "https://api.foursquare.com/v2/venues/search?ll=" . $latlon . "&limit=50&v=20131119&query=$place_e&client_id=V0TPGR31B3YQXZAV3JHADOACZJPCFC2NN1JM5X3VPYI4B1K1&client_secret=3ZOSDOEY5SABBP14O45G4UQMA1JSFS4LC0LDH3C5ZI1A35MF";
  122.  
  123. if ( $url ) {
  124.     $json = file_get_contents( $url );
  125.     $data = json_decode($json);
  126.     //var_dump($data);
  127.  
  128.     //asort($data,);
  129.     //print_r($my_array);
  130.     echo "<p>Show 50 entries! This system is designed to return 50 entries</p>";
  131.     echo "<p>(you could) start typing in your ZIP in the Search: below.</p>";
  132.  
  133.     echo "<table class=\"TFTable\" id=\"busiest\" name=\"busiest\" width=\"100%\" border=1 style=\"border:black 3px solid;\"><thead><tr><th colspan=\"6\" align=\"center\">$place - $locname Latlon: $latlon <b>(10000m radius)</b><br>Picture: <img src=\"images/$place.jpg\" width=70 height=70></th></tr><tr><th>Place Name</th><th>Physical Address</th><th>Checkins Count (SORTBY click here)</th><th>Users Count (SORTBY click here)</th><th>hereNow count (SORTBY click here)</th></thead><tfoot><tr><td><td><td><td><td></tfoot><tbody></tr>";
  134.     foreach ($data->response->venues as $result) {
  135.             echo "<tr>";
  136.             echo "<td>" . $result->name;
  137.             echo "<td nowrap>" . $result->location->address . "," . $result->location->crossStreet . "," . $result->location->city . "," . $result->location->state . " " . $result->location->postalCode . "</td>";
  138.             echo "<td align=right>" . $result->stats->checkinsCount . "</td>";
  139.             echo "<td align=right>" . $result->stats->usersCount . "</td>";
  140.             echo "<td align=right>" . $result->hereNow->count . "</td>";
  141.             echo "</tr>\n\n";
  142.     }
  143.     echo "</tbody></table>";
  144. }
  145. ?>
  146. </div>
  147. </body>
  148. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement