Monday, November 26, 2012

Links to Maps from iBooks

A reader asks what happens with the Map links in the Barcelona Beyond Gaudí book now that iOS no longer has the Google Maps app. It's a good question, so I thought I'd answer it here.

In the Barcelona Beyond Gaudí book, I targeted the map request to Google:

<p><a href="#left" id="caption">A spiral decoration on the gates to Sant Pau Hospital. </a><a href=",2.174297+(Spiral%20Decoration%20on%20Gate)" ><img src="images/map.gif" alt="map button" id="mapbutton" /></a></p>

And it looks like this:

Maps in ebooks in iBooks

When your reader clicks the Map link in iOS5, iBooks passes them to the Google Maps app. In iOS6, iBooks passes such links to the Google Maps page, in Safari:

Maps in ebooks in iBooks

And the reader can still click on the Directions or Street View buttons at the bottom. Here is Street View:

Maps in ebooks on iBooks

Then a quick four finger flick, and the reader can jump back to iBooks.

To send the reader to the Apple maps app instead of the Google Maps page, you just have to target the link to the Apple maps server:

<p><a href="#left" id="caption">A spiral decoration on the gates to Sant Pau Hospital. </a><a href=",2.174297" ><img src="images/map.gif" alt="map button" id="mapbutton" /></a></p>

Then when your reader clicks the Map link, iBooks sends them to the Apple Maps app (without asking if they want to leave the iBooks app, one should note).

Note that the Apple Maps app doesn't mark where the location is on the map:

Apple Maps app from iBooks

And there doesn't seem to be a street view, though you can click the page curl in the bottom-right corner to view Satellite view and then zoom in.

Maps app from iBooks

You can get more information about creating links to the Apple Maps app in the iOS Developer Library.


  1. From that, you could have the user set a persistent cookie which would be used to set the preferredDomain variable to "apple" or "google" and run a script like this:

    <script src="js/jquery.js" type="text/javascript" charset="utf-8"></script>

    <script type="text/javascript">
    $(function() {
    var preferredDomain = "google";
    $('a[href*=""], a[href*=""]').each(function() {
    $(this).attr('href').replace(/google|apple/, preferredDomain);

    Then all links either become Google links or Apple links.

  2. A working sample — not with cookies, but you can change the value of preferredDomain — is at


More of my books