CaseWiki:Google Map Extension/markers.php

This script outputs a simple XML file with the page titles and coordinates of all pages that are geotagged with the GIS MediaWiki extension. Place it in your extensions directory and change the URL in the gmap.js file so you can plot markers on maps.

 
<?php
/*
  This script outputs a very simple XML document to be read by the Google Maps extension
 
  Gregory Szorc <gregory.szorc@case.edu>
 
*/
 
define('MEDIAWIKI', true);
require_once('../includes/Defines.php');
require_once('../LocalSettings.php');
require_once('../includes/Setup.php');
require_once('../includes/SpecialSearch.php');
 
//this should really use the wiki database connection...
$db = new mysqli('localhost','wiki-user','password', 'wiki');
 
$points = array();
 
$query = "SELECT page.page_title, gis.gis_latitude_min, gis.gis_latitude_max, gis.gis_longitude_min, gis.gis_longitude_max, gis.gis_page FROM page, gis WHERE page.page_id=gis.gis_page AND page.page_namespace=0";
if ($result = $db->query($query)) {
  if ($result->num_rows) {
    while ($row = $result->fetch_row()) {
      $p = array();
      $p['lat'] = ($row[1]+$row[2])/2;
      $p['lon'] = ($row[3]+$row[4])/2;
	
      $title = Title::newFromText($row[0]);
      $p['url'] = $title->getFullURL();
 
      $p['title'] = $title->getText();
      $p['id'] = $row[0];
 
      $points[] = $p;
    }
  }
}
 
header("Content-Type: text/xml\n\n");
 
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
echo "<markers>\n";
 
foreach ($points as $p) {
  echo "  <marker id=\"".$p['id']."\" lat=\"".$p['lat']."\" lng=\"".$p['lon']."\" title=\"".$p['title']."\" url=\"".$p['url']."\">\n";
  echo "  </marker>\n";
}
 
echo "</markers>";
 
 
?>
This page has been accessed 1,520 times.
This page was last modified 22:24, September 26, 2005 by Gregory Szorc.
About | Disclaimers