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 Blackberry (such as the Pearl), you're likely to have the Blackberry 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 Blackberry, so it makes sense to convert them to Google Maps URLs for the 99% of the world that doesn't have a Blackberry.

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 PHP 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 Blackberry Maps URLs to Google 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 Blackberry Maps, copy my location, paste the URL into the form, post it to the script, and paste the result in the Blackberry's Google/Talk 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 iPhone 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 Google/Maps).

In the meantime, happy Twittering!

See Also: