Status
door is becoming closed so people stop coming in
Location
Herndon, VA
Subscribe to GeoRSS Subscribe to KML


How to create geolocated posts in Blogger

Published in Environment, Geolocation, Javascript, Web  |  6 Comments


GreenerMaps screenshotI’m helping out on a project, GreenerEarth, which is a location companion site to the GreenerMagazine set of environmental weblogs.

For various reasons, they’re using Blogger to currently run their weblogs since it’s free, easy to setup, and easy to use for non-technical people.

The goal of GreenerEarth was to create a companion weblog that provided maps and locations to the various articles that will appear on GreenerEarth. The difficulty resides in the severe restrictions using an hosted blogging tool places on creating a dynamically generated maps. I wanted to allow the writers to easiliy create new posts, put in locations, and then just ‘post’. The actual page would handle parsing the post for the location data and then creating the resulting map.

The only access you have in Blogger (at least) is the main template page, and post templates. Therefore, the solution calls for a marked-up post with lots of tags, and heavy Javascripting of the DOM to dynamically create an array of locations and put these on a GoogleMap.

The result is the ability for any blog author to write a post using the template and the resulting post to have a map with the multiple (or single) locations and article body. As the user clicks on locations in the map, the detailed description shows itself and a bubble shows the summary and link to the site’s homepage.

The nitty-gritty

The post template looks like this:


The fields should be pretty self-explanatory. The GeoRSS microformat is still being standardized, and hasn’t yet been defined for marking up XHTML content. So I made an ad-hoc solution. A filled out post would then look like so:


Sustainable Diamaonds
Diavik diamond mines are sustainable Mines located in the Northwest Territories.
Diavik diamond mine
Lac de Gras
Northwest Territories
Canada
Some Interesting information about Diamond mines

If you have multiple locations, copy the template before the

and paste it below the previous location (or in the desired order). You can add as many locations as you want. Each location will show up as locations with connecting lines on the map.

Somewhere in your template you should add the following to actually place your map. You can vary the size as desired here.


the nitty-gritty

To grab the code below in a simple form, download the source code here.

The following Javascript goes at the bottom of the Blogger template. What it does is search through the DOM (the post) and pulls out all of the location elements and then creates an array of the latitude and longitude values of the location. The summary and link are placed within the GoogleMaps popup window and then the rest of the actual location information shows or hides itself in the right-hand sidebar.


“;

var marker = createMarker(locationPoints[locationPoints.length-1], i, html, mapLocation[i]);

map.addOverlay(marker);

}
map.addOverlay(new GPolyline(locationPoints));
map.centerAndZoom(locationPoints[0], 4);

}

Finally, the appropriate CSS markup also needs to be placed in the template. Modify it as you want to make it match the rest of your blog.


#map {
    float: left;
    text-color: black;
    font-size: 12px;
    }
#map .mapMarker{
  color: black;
  width: 250px;
}

#map .mapMarkerMore {
  text-align:right;
}
.location {
    font-size: 12px;
    border: 1px solid white;
    background-color: gray;
    padding-left: 5px;
    }
.location .summary {
    color: white;
    font-size: 16px;
    border-bottom: 1px solid white;
    background-color: #9ad;
    margin-left: -5px;
    padding-left: 5px;
    display:block;
    }
.location .detail {
	display: inline;
    }
.geo_name {
    font-size: 11px;
    border-bottom: 1px;
    }

.geo_city, .geo_region, .geo_country {
    display: inline;
    margin-top: 4px;
    padding-right: 3px;
    font-size: 9px;
    border-top: 1px solid white;
    text-align: right;
    }

.greenNav {
	display: inline;
	list-style-type: none;
	padding-right: 5px;
	margin: 0px;
    }
.greenNav li {
	display: inline;
	list-style-type: none;
	border-right: 1px solid gray;
	padding-right: 5px;
    }
.hidden {
    display: none;
     }

Similar Posts


Responses

  1. Tantek says:

    January 10th, 2006 at 11:33 am (#)

    Great post!

    One minor correction. The “geo” microformat for marking up latitude and longitude information has been drafted based on subsetting the extremely popular vCard and thus hCard standard, take a look:

    http://microformats.org/wiki/geo

    But it looks like your use of “geo_…” is actually for named locations with a name, lat long, address, and a note that you can already do today with hCard:

    http://microformats.org/wiki/hcard

    E.g. instead of:

    <div class=”location” lat=”64.30″ long=”-110.17″>
    <div class=”summary”>Sustainable Diamaonds</div>
    <div class=”detail”>
    Diavik diamond mines are sustainable Mines
    located in the Northwest Territories.
    </div>
    <div class=”link”>homepage</div>
    <div class=”geo_name”>Diavik diamond mine</div>
    <div class=”geo_city”>Lac de Gras</div>
    <div class=”geo_region”>Northwest Territories</div>
    <div class=”geo_country”>Canada</div>
    </div>

    You want:

    <div class=”vcard”>
    <div clas=”geo”><span class=”latitude”>64.30</span><span class=”longitude”>-110.17</span></div>
    <div class=”summary”>Sustainable Diamaonds</div>
    <div class=”note”>
    Diavik diamond mines are sustainable Mines
    located in the Northwest Territories.
    </div>
    <a class=”url” href=”homepageurl”>homepage</a>
    <div class=”fn org”>Diavik diamond mine</div>
    <div class=”adr”>
    <div class=”locality”>Lac de Gras</div>
    <div class=”region”>Northwest Territories</div>
    <div class=”country-name”>Canada</div>
    </div>
    </div>

    By using hCard, any user will be able to add these locations to their address book.

    Give it a try!

    Thanks,

    Tantek

  2. Andrew says:

    January 10th, 2006 at 2:41 pm (#)

    I will compress the comments a single marked-up one if you don’t mind. I had a heck of a time getting it formatted in the blog body myself.

    Thanks for pointing out the microformat page. I think I tossed that in my del.icio.us links awhile ago and never pulled it back out.

    Now that I figured all this out on blogger I’m actually reimplementing it on my own server so I can do a lot more for the project. Blogger is *so* limiting, but obviously meant for the casual blogger.

    I’ll still update the current GreenerMaps page and use the geo format in the new project.

  3. Ross Belmont says:

    January 11th, 2006 at 2:11 pm (#)

    On a related note, if you run your feed through FeedBurner you can use its “Geotag Your Feed” feature to generate the geo:lat and geo:long tags.

  4. Harlan says:

    January 12th, 2006 at 9:10 pm (#)

    Andrew, As publisher of Greener Mag, I wanted to express, on behalf of the team, our sincere appreciation and “thunderstuckedness” at your ability to clabber together what, as far as we know, is the first real Blogger use of GoogleEarth maps - look out CNN…it woiks.

    We who are about to publish salute you.Your mates at Greener Mag

  5. iuxwxtyibb says:

    June 20th, 2007 at 8:54 pm (#)

    Hello! Good Site! Thanks you! lhufsofpxugaxg

  6. abhay says:

    November 21st, 2008 at 1:55 pm (#)

    very nice idea…
    i am in linux and can’t see half of your page, lots of blanck paras… any prob with my comp?

Leave a Response