GeoURL Mapping BookMarklet

Announcing the GeoURL Mapping BookMarklet release 0.1. As mentioned in my last post, I thought it would be neat if you could easily call up a map when you were looking at a web page that had a geocode — that is, a page in which the author had embedded global latitude/longitude coordinates using the conventions outlined by GeoURL or GeoTags. There aren’t all that many pages that are tagged like this, but hopefully more people will be doing it in the future. If the tool finds a tag and can parse it, it opens a new window and loads a MapQuest map centered on the page’s latitude and longitude; otherwise it pops up an alert telling you that it failed.
The JavaScript itself turned out to be not that hard to write, although I have no idea which browsers it works on. Well, I know that when it’s embedded in a test HTML page, it works on Safari and Mozilla Firebird. It just uses W3C DOM, so most newer browsers should support it. The real hassle, however, was getting the javascript to move happily into Safari’s menu bar — boy, it would be cool if browsers gave bookmarklet-type extensions first class support. As it is, you have to monkey around with URL encoding to end up with something like this:
Here is the same code without the URL-encoding, in case it helps you read it or otherwise manipulate it:

var metatags = document.getElementsByTagName("meta");
var geoloc=null;
for(var i=0;i<metatags.length;i++){
  if (metatags.item(i).getAttribute("name")){
    var name=metatags.item(i).getAttribute("name");
    if( (name=="ICBM"||name=="geo.position") 
         && metatags.item(i).getAttribute("content")) {
var re=/(\S+)\s*[,;]\s*(\S+)/;if(geoloc){
    var lat=RegExp.$1;var lon=RegExp.$2;
    var mqURL=""+lat+"&longitude="+lon+"&zoom=8";
    alert("couldnt parse location: " + geoloc)
} else { alert("no location meta-tag found"); }
It works pretty well on GeoURL pages — I have tried a sampling of my neighbors and it works on most that I’ve tried. It failed on the one or two GeoTags pages I tried, but that project seems to have a lot less activity that GeoURL. You are encouraged to use the above, but I make no offer of support at all — the reasons it is likely to break are the most tedious and boring problems to solve. I copied and pasted the above into a Safari Bookmark and it worked; however, I did the same with Mozilla Firebird and it didn’t. Fortunately, I use Safari a lot more than I use Mozilla.

One thought on “GeoURL Mapping BookMarklet

  1. Pingback: Through The Wire

Comments are closed.