If you would like to give your Wordpress RSS feed full GeoRSS compatibility, it’s really quite simple - all you need to do is copy and paste the following piece of code into your functions.php file:

function geo_header() {
echo 'xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:georss="http://www.georss.org/georss"';
}
add_action('rss2_ns', 'geo_header');

function geo_points() {
global $wp_query;
$map_lat_geo = get_post_meta($wp_query->post->ID, 'map_lat', true);
$map_long_geo = get_post_meta($wp_query->post->ID, 'map_long', true);
echo '<geo:lat>' . $map_lat_geo . '</geo:lat>';
echo '<geo:long>' . $map_long_geo . '</geo:long>';
echo '<georss:point>' . $map_lat_geo . ' ' . $map_long_geo . '</georss:point>'; }
add_action('rss2_item', 'geo_points');

However, please remember that in order to view the GEO-Tagged RSS feed, you will need to use the full URL, such as http://yourdomain.com/?feed=rss2

You may be asking how can you then add coordinates to posts…?

Also relatively simple - just create custom fields labeled:

map_lat
map_long

…As referenced above within the code.

If you need a really easy way to find the coordinates you need, we strongly recommend the use of the Mapeed.AdressChooser API

If you’re looking for an example of what can then be done with the Geo-Tagged RSS Feed, please take a look at the following:

The KL News Network Geo-Tagged Page, which does not use any plug-ins:

This hack has been provided for those looking to incorporate Geo-Blogging functionality directly into their theme, or that need a step in the right direction as far as developing your first Geo-Tagged plug-in may be concerned.

For those curious as to exactly what code is needed to generate a map like the one seen above, all you need to do is include the following code:

<script src="http://www.google.com/jsapi?key=MUST ADD YOUR API KEY HERE">
</script><script type="text/javascript">google.load("maps", "2");</script>

<script type="text/javascript">
var map;
var geoXml;
var toggleState = 1;

function loadMap() {
if (GBrowserIsCompatible()) {
geoXml = new GGeoXml("http://klews.net/?feed=rss2");
map = new GMap2(document.getElementById("map_canvas4"));
map.setCenter(new GLatLng(3.15021,101.707703), 10);
map.addControl(new GLargeMapControl());
map.addControl(new GLargeMapControl());
map.addOverlay(geoXml);
}
}

function toggleMyKml() {
if (toggleState == 1) {
map.removeOverlay(geoXml);
toggleState = 0;
} else {
map.addOverlay(geoXml);
toggleState = 1;
}
}
google.setOnLoadCallback(loadMap);
</script>

<div id="map_canvas4"></div>

 

Read More From The WP Hacks Category

 



  1. Those interested in geo-blogging should really check-out WPMU gMaps!

     

 

Powered by WP Hashcash