Status
someone checked in 4.2GB of data files in my subversion repo. makes a global checkout "unfun"
Location
Alexandria, VA
Subscribe to GeoRSS Subscribe to KML


Geolocation

MapQuest OpenAPI?

Published in Geolocation, Maps, Open-Source, Programming


I wish I could attend more conferences on geeky tech stuff - but being in the Midwest, and primarily just a hobbyist on cutting-edge tech stuff, I can’t go to all the kewl kidz conferences. I still troll the session lists and try to grab presentations and papers when they’re available, which is far-too-little for the O’Reilly confernences.

While drooling over the upcoming O’Reilly Emerging Tech conference I noticed the session: Building More Useful Mashups: Integrated Routing and Geocoding talk being given by Antony Pegg of MapQuest. However, searches turned up no such API. I guess this API will be announced and released as part of the ETech ‘06 conference.

The synopsis looks really interesting. Especially since it will offer truly supported routing and geocoding, rather than the current method of using unsupported features of the other major mapping API’s.

Free mapping APIs unleashed the creativity of the developer community by allowing anyone to display data on a map. However, existing APIs haven’t given developers a complete tool kit. MapQuest’s OpenAPI is the first to offer integrated routing and geocoding and we’ll showcase how you can use these capabilities to build more useful web mashups.

The name “OpenAPI” is obviously a to distinguish this new service from their from their current AdvantageAPI or GeographicCoverage POI database, both of which are commercial licensed interfaces to the MapQuest data.

Update: May 16, 2006 - just an update for anyone that finds this blog entry. The MapQuest OpenAPI is a pretty slick set of interfaces for putting up maps, and most importantly routes in a page or application. I’ve submitted several competition entries, some of which include the GreaseRoute mapping scripts for showing routes and locations of Microformat enabled addresses, and MapThis which hijacks the GMail “MapThis!” link that shows up when an email has an address.

There is another mashup that is currently in beta testing with users. Let me know if you’re interested in trying it out.


Spatial programming with Ruby on Rails

Published in Geolocation, Howto, Programming, Ruby


Many of my projects employ a spatial aspect. I am fascinated by location, context, community, and of course, the technology that drives this all. I created my travelogue a while ago, but it’s rather dated, buggy, and not fun to maintain or update since it’s all written in PHP as I was learning PHP.

I’ve really gotten “rolling with rails” (pun intended). One of the factors that really excites many developers is an active community. This can be seen by observing the Mac community (hyperlink any number of weblogs, fan sites, howtos, books, et al. here), car clubs, kennel clubs, etc. Ruby and Rails are both pumping out huge numbers of plugins, add-ons, and howtos that further fuels the fire.

However, there aren’t currently any good spatial libraries or support within RoR. Specifically, I would like to store general geometry information (areas, points, lines) in a database, create the model in Rails, and then query the model with code like: @user.get_within_radius(:users, 50).

Databases and GIS

My biggest difficulty is that my shared host (Dreamhost) does not provide PostgreSQL databases, only MySQL. As anyone in the GIS field knows, PostGIS, an extension module for PostgreSQL is the requirement for proper spatial database storage and retrieval. Instead of storing locations as a pair of floats, true geometry in the form of POINT, POLYGON, CURVE, and others are used.

MySQL Spatial Extensions are began to emerge in MySQL 4.1. However, as this article on GIS and Spatial Extensions with MySQL points out, many of the core functions are missing (most notably Distance()). This is true even in the current MySQL 5.0. The result is having to do more complex queries to get distance information:

SELECT
  c.cab_driver,
  ROUND(GLength(LineStringFromWKB(LineString(AsBinary(c.cab_loc),
                                             AsBinary(a.address_loc)))))
    AS distance
FROM cab c, address a
WHERE a.address = 'Foobar street 110'
ORDER BY distance ASC LIMIT 1;

In the meantime, there are several stop-gap solutions. Bryan Wood (glytch.com) put together a Ruby library file that provides a small number spatial operation utilities, and is useful for operating on the “simple database scheme” of a latitude, longitude pair of float columns. The operations are performed by doing a simple SQL query where the latitude and longitude are within max/min bounds. This can’t handle radius or spherical operations quickly, but is good for a rough estimate.

For an actual spherical measurement, you can do the following in your ruby code (via GeocodeAmerica):

@places = Place.find_by_sql ["select p.* from places p where
     ((3963.0 * acos(sin(p.latitude/57.2958) *
       sin(?/57.2958) +  cos(p.latitude/57.2958) * cos(?/57.2958) *
        cos(?/57.2958 - p.longitude/57.2958))) < ?)",
        lat, lat, lon, distance]

Extending Ruby on Rails

A better solution would be to develop a model that provides a GIS interface to a PostGIS or other OGC-style database. This requires extending the Ruby on Rails model to arbitrary column data types, and then providing the data types as getters/setters.

Given the SQL create cod:

CREATE TABLE address (
  address CHAR(80) NOT NULL,
  address_loc POINT NOT NULL,
  PRIMARY KEY(address),
  SPATIAL KEY(address_loc)
);
class Address < ActiveRecord::Base
        def address_loc=(textrepresentation)
           write_attribute(:address_loc,
           Address.find_by_sql(["SELECT GeomFromText(?)
as value", textrepresentation]).first.value)
        end

        def address_loc
          Address.find_by_sql(["SELECT AsText(address_loc) as value
FROM addresses WHERE id = ?", id]).first.value
        end
end

Geocoding

Geocoding is the act of converting a location name (major name, street address, etc.) into latitude and longitude (or whatever your preferred numerical location representation may be).

Ruby Geocoding Resources


GPS and Maps on Mobile

Published in Gadgets, Geolocation, Maps, Mobile, Nokia


I’m trying out several mobile mapping solutions. None of them are really great, and none of them (apparently) are ‘hackable’. It’s very easy to get location information from GPS, network, or the user. What’s not easy is getting and using maps. Projects like OpenStreetMap are trying to create shared, open maps for users. But this is a long way off, and will never have the support and infrastructure that the commercial map providers have.

ThoughtFix has a plea to Nokia to provide a mapping application for their Nokia 770, and points out the (hereforeto unbeknownst to me) Route66 Mobile which can run on my Nokia 6600. I already have a BlueLogger GPS, so the $300 price-tag including GPS unit is a bit steep, though the package does include lots of goodies (RS-MMC memory card, card reader, GPS unit car charger, phone car mount).

What would be great, however, would be able to use the map files included with Route66, or Delorme Handheld StreetAtlas, or any other maps meant for a mobile platform (small resolution, small file size). Then developers could provide additional solutions and add-ons via their favorite programming medium. The high-cost of map delivery really precludes innovative, market-risky application development.


How to create geolocated posts in Blogger

Published in Environment, Geolocation, Javascript, Web


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;
     }

Obtaining Latitude & Longitude

Published in Geolocation, Maps, Travel


I use several techniques for getting the latitude and longitude of a location. It depends on what info I have available:

  • Geeky - requires some forethought, batteries, and sky. Use a GPS receiver (esp. something slick like a Bluelogger or Navizon) to store your waypoints and tracks.
  • Quick & easy - if you’re in the US, use a geocoder, like geocoder.us. It only requires an address, location, city, state and you’re done. It would even be easily automatable (lots of people do this).
  • Slick but tedious - works anywhere in the world: gmap_extras greasemonkey script for Firefox adds latitude and longitude to GoogleMaps. Unfortunately, Google keeps changing their layout which breaks the Greasmonkey scripts.
  • National Geographics’ Topo! is a little overkill, and very clunky interface. It is obviously a straight-port from Windows. In fact, the box and menus all say that you can export to Palm or PocketPC, but after lengthy discourse with National Geographic (well, Topics Entertainment) it was verified that this was not the case. Still, very details latitude, longitude, and altitude