Hacking Google Maps and Google Earth (ExtremeTech)

(Dana P.) #1

Chapter 14: Merging with Flickr Photos


For the latitude/longitude values, you should supply a floating-point value, just as with any
other value used within Google Maps.

How you obtain the latitude/longitude of your photo is entirely up to you. Some users are
beginning to record photo locations with a simple GPS receiver when the photo is taken.
Others just use Google Maps to locate the position where the photo was taken. If you are
uploading a number of photos that were taken at similar locations, you can tag photos in
groups or during upload to specify the geotaggedinformation in bulk.

Adding Flickr Photos to a Google Map


Adding Flickr photos to a Google Map based on their geographical tags is a two-phase pro-
cess. First, you need to search for the photos that you want to overlay on the map. The search
process will return the photo ID information (as demonstrated earlier). However, to obtain the
tags, and therefore the embedded geographical information, the info for each photo must be
individually obtained to determine where the photo should be placed on the map.

Before that, though, you need to get around a security issue built into most browsers.

A Flickr Proxy


Most browsers do not allow you to send XML HTTP requests like those used in Google Maps
applications to domains other than the source of the HTML file they are being loaded from.
There are ways to get around this issue on certain browsers, but none that are compatible across
a range of different browsers without writing complex JavaScript to change the security prefer-
ences. Even where it is possible, users will normally have to accept some security message that
may also reduce the security of their browser.

The easiest way to get around the issue is to provide a proxy service that passes on the request
from the Google Maps application through the server used to host the HTML and then on to
the destination service (in this case Flickr). The data can then be echoed back verbatim to the
script as if it had directly accessed the remote service.

A sample proxy service, here written in Perl, is as follows.
use strict;
use CGI qw/:standard/;
use LWP::UserAgent;

my $ua = LWP::UserAgent->new(env_proxy => 1,
keep_alive => 1,
timeout => 30,
agent => “Mozilla/5.0 (X11; U; Linux i686; ;
en-US; rv:1.0.2) Gecko/20021120 Netscape/7.\
01”,
);
Free download pdf