Newer
Older
Digital_Repository / Repositories / Maps / google_generate_data.php
nstanger on 8 May 2006 1 KB - Added various test files.
  1. <?php
  2.  
  3. include('geoipcity.inc');
  4.  
  5. $gi = geoip_open('/usr/local/share/GeoIP/GeoLiteCity.dat',GEOIP_STANDARD);
  6.  
  7. $connect = mysql_pconnect ('localhost','eprintstatspriv','AuldGrizzel');
  8. $db = mysql_select_db('eprintstats',$connect) or die("Could not connect");
  9.  
  10. $query = "SELECT ip, COUNT(*) AS count FROM view WHERE (view_type = 'download') GROUP BY ip ORDER BY count DESC LIMIT 500";
  11. $result = mysql_query($query,$connect);
  12.  
  13. if (mysql_num_rows($result) > 0)
  14. {
  15. $i = 0;
  16. while ($row = mysql_fetch_assoc($result))
  17. {
  18. $ip = $row["ip"];
  19. $count = $row["count"];
  20. $location = GeoIP_record_by_addr($gi, $ip);
  21. if (isset($location->latitude))
  22. {
  23. $lat = $location->latitude;
  24. $long = $location->longitude;
  25. $city = $location->city;
  26. if ($city == '') $city = 'Unknown';
  27.  
  28. $cities[$city]['lat'] = $lat;
  29. $cities[$city]['long'] = $long;
  30. if (!isset($cities[$city]['count'])) $cities[$city]['count'] = 0;
  31. $cities[$city]['count'] += $count;
  32. }
  33. }
  34.  
  35. print "<markers>\n";
  36. foreach ($cities as $city => $loc)
  37. {
  38. print '<marker lat="' .
  39. $loc['lat'] .
  40. '" lng="' .
  41. $loc['long'] .
  42. '" city="' .
  43. $city .
  44. '" num="' .
  45. $loc['count'] .
  46. '" />' . "\n";
  47. }
  48. print "</markers>\n";
  49.  
  50. }
  51.  
  52. ?>