In previous post Calculating the length of Google Maps line segments I presented a program that calculated the length of line segments drawn in Google Maps. Today Google Maps incorporated a new feature exactly for this purpose. If you go to your maps and click on the line segment, a popup appears on the map that contains the length of the segment. Look where the red arrow is pointing in the following screenshot:
So if you'r planning your next biketrip, you now know the distance instantly. Nice.
My script calculated the biking trip from my work to home is 36.35 kilometer and Google Maps reports 25.74 kilometer. I wonder who's most correct ?
Cast for two
Tuesday, September 18, 2007
Now in Google Maps: length of line segments
Posted by
cast42
at
2:42 PM
3
comments
Labels: Google Maps, news
Saturday, August 25, 2007
New feature in Google Maps: embed into html
Google announced a new feature of Google Maps. Go to "My Maps"/"Mijn kaarten" on maps.google.be and click on "Link to this page"/"Link naar deze pagina". Two textfields appear:
Embedding the HTML in the second text box under "HTML in website plakken":
<iframe width="425" height="350"
frameborder="no" scrolling="no" marginheight="0" marginwidth="0"
src="http://maps.google.be/maps/ms?ie=UTF8&hl=nl&msa=0&
msid=106593127569810234189.000435c68e072f63d1f57&om=1&
ll=50.916561,4.699123&spn=0.090651,0.05137&
output=embed&s=AARTsJpF3cBYZmrDjYcLS8foVeBIWCBK5A">
</iframe><br/>
<a href="http://maps.google.be/maps/ms?ie=UTF8&hl=nl&msa=0&
msid=106593127569810234189.000435c68e072f63d1f57&
om=1&ll=50.916561,4.699123&spn=0.090651,0.05137&
source=embed"
style="color:#0000FF; text-align:left;font-size:small">
Grotere kaart weergeven
</a>
renders in this blogpost as:
Grotere kaart weergeven
which will show up right on your blog but might leave just a blank spot in your feed reader. Let me know in the comments how it works with your feed reader.
If you click on "Ingesloten kaart aanpassen en voorbeeld ervan weergeven", you get the ability to alter the defaults of the generated HTML:

Basically, it allows to alter the size of the included map. It's a pitty that you can not influence the controls that appear on the map.
Posted by
cast42
at
11:59 AM
1 comments
Labels: belgium, Google Maps, howto
Thursday, July 19, 2007
Calculating the length of Google Maps line segments
A few days ago, I decided to bike home from work (from Brussels to Leuven). Inspired by the "gefietst" blog en based upon the route here I made my adapted route to get to my home. The bike trip went well. Of course, I was wandering how long the bike trip was. Since I have a basic bike with no equipement to measure this I had to resort to the Google Maps info. I was almost sure that a webservice would exist that calculated the length of linesegments of Google Maps or from a KML file but after some searching I found no easy way to do this via the web. (If somebody would be aware of such a service, please drop me a line in the comments) Therefore, I decided to write a small Python script to calculate the lenght of all lines drawn on a Google Map. Just go to your map, click on "Link to this page", copy the URL and fill the URL in the Python script. Run the Python script and, bingo, you have the length in kilometers for every continuous linesegment. Here's the code:
The output of the above script is:
distance of fietsweg is 36.35 kilometer
Of course, this calculation is only an approximation since the trajectory is only an approximation (albeit a pretty good one) of the real route I followed and no heigth information is taken into account. Still I guess that its accurate upto a few kilometers. If somebody has a spare Bluetooth GPS receiver, you can always send me one ;-).
The calculation of the distance in kilometer between two points is based on the code in Ruby and the examples from the zips project a sourceforge. The coordinates of the linesegments are obtained from the KML file that Google Maps generates when appending &output=kml to the URL from 'link to this page'. The KML file is parsed using the Python minidom module. I hope that in the future Google will provide a "&output=jsonp&callback=calcfunc" so that a simple webpage with some Javascript can calculate the length. But that's for another programming project.
Posted by
cast42
at
4:05 PM
9
comments
Labels: biking, calculation, distance, Google Maps, KML, python
Wednesday, July 04, 2007
Twitter tweets on Goople maps mashup
I figured out a simple way to make a mashup that displays tweets from twitter on a Google Map. Click on the pin and a window pops up containing the last tweet that was updated. It is easy to change the location of the pin or the twitter feed that is addressed to obtain the latest tweet. For your reference, here's a pretty print of the code using Google Code Javascript code prettifier:
Here is how it works:
Twitter API rocks with a JSON feed for every user. Adding a callback function makes it very convient to read the data. Just call a JSON object http://www.twitter.com/statuses/user_timeline/user
http://www.twitter.com/statuses/user_timeline/user.json?callback=twitterCallback&count=1
Replace user with your Twitter nickname. In my case, it's cast42.The count parameter is set to 1 such that only the most recent tweet is obtained.
var tweet = new Object;
function twitterCallback(obj) {
tweet.text = obj[0].text;
}
The full source code can be downloaded from the example. Don't forget to fill in your own Google Maps key and replace cast42 with your own twitter name.
Posted by
cast42
at
9:59 PM
0
comments
Labels: google, Google Maps, Javascript, json, maps, mashup, twitter