Friday, 6 June 2014

Finding the name and altitude of your location

If you know the latitude and longitude a location, how can you get additional information about the place? There are a lot of APIs and web services that will tell you. This blog post focuses on a web service from the Norwegian Mapping Authority, which will give you the name, altitude and terrain type of your location.

In my previous blog posts (1, 2, 3, 4) I showed you how to use a SPOT Satellite Messenger to track your trips. This will give you a series of latitude and longitude points, and the time they where recorded, but that's about it. For my expedition map, I'm especially interested in the altitude of my location, which can be used to draw a height profile of the track. I would also like to show the name of the places I've been.

Luckily, the Norwegian Mapping Authority ("Kartverket") provides such a service with a great level of detail. The service allows you to send in a latitude/longitude position, and obtain the altitude, nearest place name and the terrain type. The service is described in Norwegian on this page.

Let's try with my current position:
  • Latitude: 59.339
  • Longitude: 5.967
This URL will give you some facts about the place:[lat=59.339;lon=5.967;epsg=4326]

The WPS format is quite verbose, but you should be able to parse out the data you need:

What does it tell me:
  • I'm just 3.6 meters above sea level.
  • The terrain type is "Åpent område" (open area)
  • The nearest place name is "Norde Breivik"
  • The place id (SSRID) is 1196378. I can use this id to get more information about the place.
Everything seems correct from where I'm sitting :-)

Photo of my location from last evening.

I've created a PHP script to parse out the values from the XML. I'm running this script as a cron job to
add information to the SPOT Satellite Messenger locations I already got in CartoDB.

I'm then able to show information about the track in the popups:

In the next blog post, we'll add some weather information to our map.


Unknown said...

Since this was a kayak trip, can you address avoiding drawing over land? A geofencing approach might work here.

Unknown said...

Hi Mano!

Very true, it's a strange track for a kayak trip. I'm mainly going to use it on land so I don't bother at the moment ;-) Would be interesting to dig into geofencing though.