Locating your photos on Google Maps
January 27th, 2012 at 9:21 am by Dr. Drang
Back in October I wrote a little script that added GPS location information to photos. My idea was to be able to take one photo with my iPhone, which would capture the location in its EXIF metadata, and use the script to transfer that information to all the photos I took with my regular camera at that same location. It works well, and I’ve been using it ever since, but once I had a bunch of photos with location info in them, I needed a tool that would do the converse: show me where they were taken. It turned out to be very easy to write.
The October program is called coordinate, and I use it like this:
coordinate -g iphone-photo.jpg IMG*
This reads the GPS metadata from the iphone-photo.jpg file and writes it to all the files that start with IMG. The new program is called map, and when I call it,
map photo.jpg
it reads the GPS info from the image file and opens Google Maps in my browser with a marker at the photo’s location.
Here’s the code for map:
python:
1: #!/usr/bin/python
2:
3: import pyexiv2
4: import sys
5: import subprocess
6:
7: try:
8: # Open the photo file.
9: photo = sys.argv[1]
10: md = pyexiv2.ImageMetadata(photo)
11: md.read()
12:
13: # Read the GPS info.
14: latref = md['Exif.GPSInfo.GPSLatitudeRef'].value
15: lat = md['Exif.GPSInfo.GPSLatitude'].value
16: lonref = md['Exif.GPSInfo.GPSLongitudeRef'].value
17: lon = md['Exif.GPSInfo.GPSLongitude'].value
18:
19: except:
20: print "No GPS info in file %s" % photo
21: sys.exit()
22:
23: # Convert the latitude and longitude to signed floating point values.
24: latitude = float(lat[0]) + float(lat[1])/60 + float(lat[2])/3600
25: longitude = float(lon[0]) + float(lon[1])/60 + float(lon[2])/3600
26: if latref == 'S': latitude = -latitude
27: if lonref == 'W': longitude = -longitude
28:
29: # Construct the Google Maps query and open it.
30: query = "http://maps.google.com/maps?q=loc:%.6f,%.6f" % (latitude, longitude)
31: subprocess.call(['open', query])
It uses the standard sys and subprocess libraries and the distinctly non-standard pyexiv2 library. Installing pyexiv2 isn’t the hardest thing in the world, but it takes more than a simple pip pyexiv2. I have a writeup on how to do it via Homebrew if you’re interested.
The script is easy to read, I think. Lines 9-17 get the name of the file from the command line, open it, and extract the GPS information. If there’s a problem in any of those steps, an exception is raised, and Lines 20-21 print an error message and quit.
Because the latitude and longitude are returned in an odd format (a list of three Fractions, one each for degrees, minutes, and seconds), Lines 24-27 are needed to put them in a format we can use to query Google Maps. The query is then constructed in Line 30, and Line 31 sends it to OS X’s wonderfully useful open command to be opened in the default browser. The Google Maps API automatically drops a marker at the location and centers the map around the marker.
I could extend the query with more parameters to set the zoom level, force the display to satellite, map, or street view, and so on, but I prefer to stick with the defaults.
There are some obvious improvements I could make:
- Add an option to use Bing instead of Google Maps. With aerial photos, Bing’s oblique bird’s eye view is often more useful than Google’s top view. I haven’t looked yet, but I assume Bing can be queried through the URL just like Google Maps can.
- Rewrite it for a library that’s easier to install than
pyexiv2. This wouldn’t affect me, but would make it easier for others to use. - Turn it into a Service. This is a trivial change that would produce a big improvement in usability. With a Service, I could just right-click on an image in the Finder and get the location by choosing an item from the popup menu.
If you’re wondering why I don’t just use iPhoto’s built-in mapping tools, it’s because I don’t use iPhoto. I find it very clunky and slow, and its organization system doesn’t work for the photos I take for my job (which is most of my photos). The map script gives me a quick way to check the location of any photo, regardless of where it’s stored on my computer.
Old problem, new trick
January 26th, 2012 at 10:49 pm by Dr. Drang
I went on a business trip to upstate New York this week and tried out a new system for keeping track of my expenses. It’s simple enough that I might actually stick with it.
There are a bunch of expense tracking apps for the iPhone. Most of them either require you to open some sort of web-based account, which I didn’t want for privacy reasons, or ask you to enter a bunch of information on your phone, which I didn’t want for tedium reasons. After looking things over, I decided to combine a few things I use already: JotNot Scanner Pro, email, and a Numbers expense report template.
I wrote about JotNot back in October. It’s a simple app that uses your iPhone camera as a scanner. What makes it different from the standard Camera app is that it crops, straightens, corrects for perspective, and equalizes the tone of your photos.
It turns out that this, combined with its ability to email the adjusted image, is all I really need.
In the past, I’d collect receipts during my trip and staple them to my expense report, which I’d make out when I got back to the office. This was pretty simple and hard to beat for efficiency, although I did have to be careful to keep my receipts together until the trip was over. If a client wanted a copy of my receipts, I’d lay them out on our scanner and turn them into a PDF that I could email along with the invoice. This was the part I hated. My company’s scanner, although networked, can’t be run from my Mac. I have to save the scans to a Windows machine and then log on to that computer from mine to get at them. If the scanner messes up—OK, if I mess up in using the scanner—I have to go back and forth between offices to redo it.
Scanning receipts in JotNot and mailing them to myself turns out to be really convenient. By default, JotNot puts its name in the text of the email, so when I get back to the office, I just search for “JotNot” in my inbox and drag the various receipts out of their mail messages and into my Numbers expense report.
There’s not much to my expense report. It’s just a simple Numbers template, a single sheet with two tables on it—one for the date of the report and one for the expenses themselves. I’m not a big fan of Numbers, but the ability to lay out separate tables on the same sheet works nicely for this kind of document. The date of the report doesn’t have to be regimented into the same grid structure as the expense details.
As I said, I drag the emailed receipts out of Mail and into Numbers, putting them on separate pages so they don’t block the table. The Show Print View command from the View menu is handy for making sure the edges of the receipts don’t leak over onto other pages. I print out a copy for our bookkeeper to use when comes in to cut our expense checks and “print” another copy as a PDF to email to the client along with the invoice.
Numbers allows you to rotate and resize images, so it’s easy to squeeze several receipts onto a single page. One thing I don’t like, and don’t understand, is that images dragged into Number always appear initially at the upper left corner of the first page, not where I “let go” of them. So after dragging them into Numbers, I have to drag them around within Numbers to get them where I want. This could be improved.1
There is, obviously, not much to my expense report template, but if you want to use it as a starting point to make one of your own, you can download a zip file of it. After expanding it, just double-click on the file to open it in Numbers. Make the changes you need, then choose Save As Template… from the File menu. It’ll available to choose from the template picker whenever you want to make a new spreadsheet.
-
It’s possible that it has been improved. I’m using Numbers ’08, which is one behind the latest version. I’d be happy to upgrade, but the current version is ’09, and I refuse to upgrade to something that’s already 3 years old. Like David Sparks, I feel certain the whole iWorks suite is on the verge of getting a new version. The problem is we’ve both been certain about it for months and Apple still hasn’t come through. ↩
Layers
January 24th, 2012 at 8:19 pm by Dr. Drang
I liked just about everything about this Tim Bray post from a couple of days ago. It’s called “Browser Sedimentation,” and it’s about the layers of non-content (sometimes called “chrome”) that have built up in today’s browsers. Here’s what my Safari looks like most of the time:

Title bar, tool bar, bookmarks bar, tab bar. The main difference between this browser sediment and river sediment is that these layers accumulate at the top instead of the bottom.1
The one thing I sort of disagree with is this:
The problem is that people like me (and I bet most readers here) can’t even see that there’s a jumble; the sediments of infrastructure are clearly separated in our understanding and thus our eyes. But occasionally I get a flash of how it must look to civilian eyes, and it doesn’t make me happy.
As one of his commenters, Ben Meadowcroft, said, the browsers of non-expert users usually have even more layers. I was reminded of this bit from Mike Lacher’s epic tale from McSweeney’s on fixing a non-expert’s computer:
With a resounding click he opened Internet Explorer 6 and gazed deep into its depths, past the Yahoo toolbar, the MSN toolbar, the Ask.com toolbar, and the AOL toolbar. And then did he see, at long last, that The Google did load.
My mom’s computer has some awful, branded version of Internet Explorer running on it, and the toolbars take up so much of the window it feels like you’re looking at the web between the slats of Venetian blinds. But she likes all that crap. When I’ve suggested getting rid of some of the tool bars, she’s been horrified; it wouldn’t be her familiar web experience without them.
I’ve always thought this was the real story behind the software that John Gruber highlights in his occasional User Interface of the Week posts. It’s not so much that the designers of these applications have no taste, it’s that their users have no taste. There’s something about an ugly, cluttered user interface that says “computer” to the great majority of users out there.
-
Except for the status bar, which I forgot to mention. ↩
Radius 81/110
January 22nd, 2012 at 10:52 pm by Dr. Drang
This old warhorse has finally come up lame.
It’s a Radius 81/110 one of the Mac clones that Steve Jobs killed off when he returned to Apple. This one aped the Power Mac 8100. It’s been in use in my company’s office since 1995. At first, it was my computer (my last Mac before going Linux), then it got relegated to accounting, where it’s been since 1997 or so. Runs System 8 and FileMaker 4.
A few years ago, I migrated almost everything off of it, but it’s still our main machine for one infrequently accessed database. Or at least it was until Friday.
I noticed it was running when it shouldn’t have been and the screen was faded (more faded than usual—its monitor may be older than it is) and streaky. After a bit of investigation, I learned that no one had turned it on; some fault in the system now causes it to run continuously as long as it’s plugged it. I turned it off by switching off the battery backup after selecting Shut Down from the—do you remember?—Special menu.
The faded and streaky video is, I’m sure, a symptom of its decline and not a problem with the monitor, but I can’t test that theory as we have no other monitors with that old DB-15 connector.
I could’ve sworn there once was a Radius logo on the front of the machine.1 It must have been stuck on with an adhesive that eventually gave out. But the logo is still on the keyboard.
-
I put the Apple sticker on the side as kind of a joke. Not an actual joke. Actual jokes are funny. ↩
iBooks Author
January 22nd, 2012 at 12:44 am by Dr. Drang
Between Kieran Healy, Glenn Fleishman, Andy Ihnatko, and John Siracusa, almost everything I might have said about iBooks Author at this early date has already been said. Kieran and Glenn made the point that we’ve been hearing about computer technology revolutionizing education for decades—Kieran even got off a joke comparing iBooks Author to Encarta, something I was trying to squeeze into a tweet until I read his post. Andy made a simple little iBook1 to get a sense of how it worked. John went into too much detail (even for him) on the iBook structure and its relation to EPUB.
There are a few scraps left for me, though.
Automation
I might want to make an iBook one day, but I can’t imagine myself writing an entire book as a single “file” (it’s not a single file, but it looks like one in iBooks Author) in an environment like a word processor or page layout program. I gave up working in a word processor ages ago and have no intention of going back, but even if you like using word processors, you wouldn’t put a whole book in a single file, would you?
Assembling a book out of separate chapter or section files is where scripting would normally be used, but Andy said iBooks Author has no AppleScript commands to speak of and compared its AppleScript library to TextEdit’s. He was being generous; TextEdit’s library has a couple of minor features that iBooks Author’s doesn’t. Maybe Apple will add scripting features to a later version, but I wouldn’t bet on it; Apple doesn’t seem too keen on AppleScript anymore.2
Which raises the question of creating an iBook outside of iBooks Author. Is it possible?
Even after listening to Hypercritical, I still wasn’t sure whether any of the binary data in an iBook—from the images, sounds, and movies that may be included in it—gets bound up with the text. I was going to make a short iBook to test this, but when I heard that Andy had already done so, I just downloaded his and took a look at it.
Andy’s iBook is called Readme.Quack. When you download it, it’s in the form of a 3.4 MB zip file, called Readme.Quack.ibooks.zip. Unzip it3 and you’ll get Readme.Quack.ibooks. This is, in itself, a zipped archive, and if you run
unzip Readme.Quack.ibooks
you’ll get a file called mimetype, a folder called OPS, and a folder called META-INF. As best I can tell, all the files are plain text except the media files (images, sounds, and movies in standard formats) and a few binary plist files in the OPS/assets/hints subdirectory. The plist files could, conceivably, start off as text XML files and be compiled to binary, but I’m not sure how easy it would be to create the XML. I converted one of Andy’s plists to XML format through the plutil command,
plutil -convert xml1 content1-landscape.plist
and found that it had a <data> block,
<data>
SUJMRhAUAAAAgEdDAAAAAACAdkMAAAhCDwAAAACAR0MAAAhCAIB2QwAACEIIAAAAAIBH
QwAAiEIAgHZDAACwQQgAAAAAgEdDAAC0QgCAdkMAALBBCAAAAACAR0MAAOBCAIB2QwAA
sEEIAAAAAIBHQwAABkMAgHZDAACwQQgAAAAAgEdDAAAcQwCAdkMAALBBCAAAAACAR0MA
ADJDAIB2QwAAsEEIAAAADXVCQwAASEPzintDAACwQQgAAAAAAAAAAABeQwAA30MAAAhC
CAAAAAAAAAAAAIBDAADfQwAAsEEYAAAAAAAAAAAAi0MAAN9DAACwQQgAAAAAAAAAAACW
QwAA30MAALBBCAAAAAAAAAAAAKFDAADfQwAAsEEIAAAAAAAAAAAArEMAAN9DAAAIQggA
AAAAAAAAAAC9QwAA30MAALBBGAAAAAAAAAAAAMhDAADfQwAAsEEIAAAAAAAAAAAA00MA
AN9DAAAIQggAAAAAAAAAAADkQwAA30MAALBBCAAAAAAAAAAAAO9DAADfQwAAsEEIAAAA
AAAAAAAA+kMAAN9DAAAIQggAAAAAAAAAAIAFRAAA30MAALBBCAAAAAAA7kMAAAAAAADf
QwAAsEEMAAAAAADuQwAAsEEAAN9DAACwQQgAAAAAAO5DAAAwQgAA30MAALBBCAAAAAAA
7kMAAIRCAADfQwAACEIIAAAAAADuQwAAyEIAAN9DAAAIQggAAAAAAO5DAAAGQwAA30MA
AAhCCAAAAAAA7kMAAChDAADfQwAACEIIAAAAAAAAAAAAAAAAwDBEzcwMQg8AAAAAAAAA
AAAAAAAAZ0QAAJhBDwAAAAAAAAAAAAAAAMBmRM3MDEIPAAAAAAAAAAAAAAAAANxDAACY
QQ8AAAAAAAAAAACYQQAA3EMAAJhBCAAAAAAAAAAAAAAAAABxQ2dmdkEPAAAAAAAAAGdm
dkEAAHFDZ2Z2QQgAAAAAAAAAZ2b2QQAAcUNnZnZBCAAAAAAAAADNzDhCAABxQ2dmdkEI
AAAA
</data>
which might be hard to generate. I think if someone could crack the structure of these <data> blocks, iBook assembly could be automated. It might require a hybrid approach—using iBooks Author to generate template files, perhaps—but it seems possible. If so, authors could publish their work in several formats without having to redo the layout every time.
Update 1/22/12
Prompted by a comment from Mark Eli Kalderon, an old hand at converting plain text files from format to format, I took another look at iBooks Author and the files it uses.
First, an .ibooks file cannot be opened in iBooks Author. If you download Andy’s example, you’ll find that it doesn’t consider iBooks Author to be its parent application. The working file that iBooks Author saves to has an .iba extension; it’s only when an publication is exported that the .ibooks file is created.
An .iba file is also a zip archive, filled with JPEG, XML, TIFF, plist and color profile files. I haven’t spent any time looking into these—I just created a new file from one of the templates, changed a couple of words, and saved—but apart from the color profiles, everything is either a text file or in a standard media format. Obviously, this may change as the publication becomes larger and more complex, but it does suggest that the best way to semi-automate the making of an iBook is to create an .iba file from your source material, do your layout in iBooks Author, then export the finished iBook.
Disposable textbooks
Many people are less than enthusiastic about iBooks Author because Apple chose a non-standard format for iBooks—EPUBish, but not EPUB. They don’t want their iBooks getting locked into a format that could be abandoned in a few years. For most textbooks, though, that’s not a problem.
I’m probably not the best person to talk about this, because I love textbooks. I still have almost all of my college texts and have over the years collected many old, classic texts in engineering and structural mechanics. When I think of a textbook’s lifetime, I think in terms of decades, not years.
But most people don’t have that kind of relationship with their college textbooks. They use them for a semester and seldom refer to them later. It doesn’t matter to them if the format of the book gets orphaned. And is there such a thing as a “classic” K-12 textbook, one that continues to be used, unchanged, for years and years? It strikes me that the K-12 textbook industry is continually updating and revising its “product.” The potential for Apple to drop the iBook format some years from now might be a concern for authors, but it shouldn’t bother K-12 textbook readers.
Non-school uses
One type of textbook that hasn’t been discussed (as far as I know) is the course material for in-house training and continuing education short courses. This is an education market that’s often overlooked but seems ideal for iBooks.
Have you ever taken one of these courses? I’ve never been subjected to in-house training, but I have taken several short courses, some on my own initiative, some that were required to maintain my professional engineering license. The course material is usually a three-ring binder full of badly photocopied journal articles written by the teacher, a few book excerpts, and printouts from the course’s PowerPoint deck. These courses don’t need 500-page behemoth texts, but could really benefit from the kind of well-produced 50-100 pager that seems to be the iBooks Author sweet spot.
And frankly, although there’s much clucking of tongues over the short attention spans of these kids today, I think it’s adults—who have jobs and families and have been out of school for years—that need the extra whizziness of iBooks to hold their interest.
As for me
When Apple launched the iBookstore a couple of years ago, I thought about putting something together to sell there, but I didn’t think I could get the kind of formatting I wanted—not, at least, without far more effort than I was willing to put in. iBooks Author has me thinking about it again. If someone develops a bit of automation for it, or if I could come up with a way to use it that wouldn’t leave me screaming in frustration, I might give it a try.
-
There’s been some discussion about what to call these things. I’m going to call each publication made by iBooks Author an iBook. I know Apple made a laptop called the iBook—I had one for several years—but they’ve retired that product, and I don’t think there’ll be any confusion. The filename extension is
.ibooks, and I suspect the singular form of that is what’s going to stick, even though iBooks is the name of the app in which we read iBooks. ↩ -
I’m not keen on AppleScript, either. Like all right-thinking people, I despise it. But despite its many frustrations, AppleScript works. Tedious, repetitive actions can be scripted away. ↩
-
You don’t allow your browser to automatically open “safe” files, do you? ↩










