Twitter/Blackberry/Google/Maps/TinyURL Mashup

So, Twitter is the new Web 2.0 kid in town, and everyone's doing it. Even me, although I'm sticking to the Jabber interface and keeping it off most of the time.

But what if you're on the move and really, really want to geotag your... er... twits? Twitterings?

Well, if you've got a modern (such as the ), you're likely to have the Maps application somewhere. Which, besides supporting Bluetooth GPS devices, also lets you copy your location as an URL like this:

The thing is, those URLs are pretty useless to folk without a , so it makes sense to convert them to URLs for the 99% of the world that doesn't have a .

And Twitter's appeal lies in its short messages, so it was time for a little TinyURL magic:

<script language="php">
if( @$_POST["url"] ) {
  $szURL = $_POST["url"];
  $host = strtolower($host);
  if( $host == "" ) {
    // reformat it as a GMaps URL
    $szURL = "$lat,$lon";
    if( $_POST["comment"] ) {
      $szURL .= urlencode(" (" . $_POST["comment"] . ")");
  $szTiny =  file_get_contents("" . $szURL);
  if($szTiny) {
    echo "<a href=\"$szTiny\">$szTiny</a>";
  else {
    echo "Bad mojo, try again.";
else {
<form action="map.php" method="post">
Make tiny: <input type="text" name="url"><br/>
Comment: <input type="text" name="comment"><br/>
<input type="submit">
<script language="php">

The script above presents you with two input boxes (one for your URL, another for an optional comment that will only be added to maps), translates Maps URLs to format, asks TinyURL to shorten the result, and outputs it to your browser - all in a few seconds.

All I have to do is pop into Maps, copy my location, paste the URL into the form, post it to the script, and paste the result in the 's client.

It's a bit convoluted, I know, but I didn't want to have the script post to Twitter directly, since this way I can use a single browser bookmark for TinyURL and map URL conversion - I've been meaning to have a way to generate TinyURLs on the move for a while, and this script does that too.

With a couple of tweaks, it can also post the result to , etc., etc. - you get the idea.

I suppose this will be useful to folk with mobile phones in a number of ways, but If you're on a desktop computer with a "real" browser (until the wipes out that distinction), some enterprising soul will surely come up with a bookmarklet to do similar things (such as posting your location directly from ).

In the meantime, happy Twittering!

This page is referenced in: