Cover | Table of Contents
http://maps.google.com/, and you'll get the view shown in Figure 1-1. If you want maps of the United Kingdom, try http://maps.google.co.uk/, and you'll get the view in Figure 1-2. A similar map exists for Japan at http://maps.google.co.jp/.
http://maps.google.com/
http://maps.google.co.uk/
http://maps.google.com/, and you'll get the view shown in Figure 1-1. If you want maps of the United Kingdom, try http://maps.google.co.uk/, and you'll get the view in Figure 1-2. A similar map exists for Japan at http://maps.google.co.jp/.
http://maps.google.com/
http://maps.google.co.uk/
http://www.google.com/corporate/tenthings.html that "you can make money without doing evil." However, more of the interest in Google Maps may stem from other ideas stated on the philosophy page—for example, "The interface is clear and simple" and "Pages load instantly."http://maps.google.com"
[Hack #1]
, standard addresses work, but so does entering a city and state, or a ZIP Code alone. Street intersections also work, as long as you add a city and state.38, -122, or 38 N, 122 W. Most modern people don't relate to latitude and longitude directly, but it is a compact and precise way to mark a location.
cheese near Petaluma, CA and get a map like Figure 1-10.
http://www.marinfrenchcheese.com/), you could click on the link on the right side in the list of results, zoom in a bit, and flip to satellite view to get the view in Figure 1-11.1005 Gravenstein Hwy N, Sebastopol, CA 95472 to SFO
SFO to OAK. This pulls up the driving directions shown in Figure 1-14.
W 88th St and Broadway, NY, NY to W 92nd St and Central Park West, NY, NY. It also includes a destination mini-map.
http://maps.google.com/maps?q=W+88th+St+and+Broadway,+ny,+ny+ to+W+92nd+St+and+Central+Park+West,+ny,+ny&ll=40.789110,-73.966550&spn =0.007782,0.013467&hl=en
Key West, Fl and then click on "Link to this page."http://maps.google.com/maps?q=Key+West,+Fl&hl=en
http://maps.google.com part should be familiar. This is the basic Google Maps address. Next, /maps is a program running on Google's servers that generates maps. Web programs can accept parameters. The syntax for parameters is to start with a question mark and then put the name of a parameter, an equal sign, and the value of the parameter. If you need a second (or third, or more) parameter, you put an ampersand between the first value and the second parameter's name. So ?q=Key+West,+Fl&hl=en means there is a parameter named q with the value Key+West,+Fl and a parameter named hl with the value en.hl is the language for the results, and q is the query, or location that you are searching for. If you speak French, replace the en with fr, and so on. If you leave off the hl parameter, Google Maps will try to display things in whatever language the user's web browser prefers.q or query parameter can be any of the things that are discussed in "Find Yourself (and Others) on Google Maps"
[Hack #2]
. For example, here is the URL to a map for latitude 38 degrees north, longitude 122 degrees west:http://maps.google.com/maps?q=38,-122&hl=en?
http://mappinghacks.com/google/sample_data.xls.
<li><a href="http://maps.google.com/maps?q=1005+Gravenstein+Hwy +N.,Sebastopol,CA,95472+(O'Reilly)&hl=en"> O'Reilly & Associates</a></li>
li tag will put each line in an HTML bulleted list. You will be able to click on the name and pop up a map centered on the address that goes with that person or company.
=CONCATENATE(B4,",",C4,",",D4,",",E4,"(",A4,")")
=B4 & "," & C4 & "," & D4 & "," & E4 & "(" & A4 & ")"
1005 Gravenstein Hwy N.,Sebastopol,CA,95472 (O'Reilly)
http://del.icio.us/?http://del.icio.us/doc/about, Joshua Schacter created del.icio.us as a:…social bookmarks manager. It allows you to easily add sites you like to your personal collection of links, to categorize those sites with keywords, and to share your collection not only between your own browsers and machines, but also with others.
http://del.icio.us/register and picking a username and password, you can use the service to bookmark your own links.
http://del.icio.us/tag/gmaps. Or to see the sites tagged with gmap, try http://del.icio.us/tag/gmap. Other people use googlemaps and google_maps, so you can get to those with http://del.icio.us/tag/googlemaps and http://del.icio.us/tag/google_maps.http://maps.google.com is awesome, with an easy user interface, one-box searching, and integrated satellite imagery. But it gets better! The Google Maps team has made it possible to include Google Maps with almost all of its great features onto your own web pages. They have done this by providing an open Application Program Interface, or API.Target=_new to open a new browser window.http://mapserver.gis.umn.edu) is very powerful, allowing you to do things that Google Maps cannot yet equal, but there is a rather steep learning cliff. There are also industry standards for web mapping promulgated by the Open Geospatial Consortium (OGC) at http://www.opengeospatial.org.http://openlayers.org/ to access public data sources and put free maps on your page.http://maps.google.com is awesome, with an easy user interface, one-box searching, and integrated satellite imagery. But it gets better! The Google Maps team has made it possible to include Google Maps with almost all of its great features onto your own web pages. They have done this by providing an open Application Program Interface, or API.Target=_new to open a new browser window.http://mapserver.gis.umn.edu) is very powerful, allowing you to do things that Google Maps cannot yet equal, but there is a rather steep learning cliff. There are also industry standards for web mapping promulgated by the Open Geospatial Consortium (OGC) at http://www.opengeospatial.org.http://openlayers.org/ to access public data sources and put free maps on your page.http://geocoder.us/, is a free U.S. address geocoder. You can go to the web site and get the latitude and longitude for a U.S. street address. You can also use a web service interface to get the latitude and longitude automatically for a group of addresses
[Hack #62]
. You can geocode using Google Maps by scraping their search results, but it's not a part of the official API, and doing so violates Google's terms and conditions of service. By contrast, the Geocoder.us site is based on free data without limited terms of service for non-commercial use.http://www.naffis.com/maphacks/latandlon.html you can click on a map and have the corresponding latitude and longitude displayed in a Google Maps info box.
http://mappinghacks.com/projects/gmaps/click.html there is a simplified example of updating a form from the coordinates of a click on a map.<form> Latitude: <input type="text" value="38.4094" id="click_lat" onclick="this.blur()"> Longitude: <input type="text" value="-122.8290" id="click_long" onclick="this.blur()"> </form>
centerAndZoom( ) now comes from these form elements. This code defaults to starting at 38.4094 N, 122.8290 W. Change those values to change the initial focus of the map. The important change to the script is the addition of a GEvent.addListener. This code and the above form can be pasted into the body of your HTML page. Change the developer's key and you can capture clicks on a map:
<script src=
"http://maps.google.com/maps?file=api&v=1&key=replacewithyourkey"
type="text/javascript">
</script>
<div id="map" style="width: 400px; height: 300px"></div>
<script type="text/javascript">
//<![CDATA[
var map = new GMap(document.getElementById("map"));
map.addControl(new GSmallMapControl());
// center and zoom to the lat/long in the form
map.centerAndZoom(new GPoint(
document.getElementById('click_long').value,
document.getElementById('click_lat').value), 3);
GEvent.addListener(map, 'click',
function(overlay, point) {
if (point) {
document.getElementById('click_lat').value = point.y;
document.getElementById('click_long').value = point.x;
}
}
);
//]]>
</script>
http://www.sueandpaul.com/gmapPedometer/ shown in Figure 2-6 estimates cumulative distance—and even includes a calorie counter.
if (navigator.appName == 'Microsoft Internet Explorer'){
document.ondblclick = handleDblClick;
bIsIE = true;
} else {
window.ondblclick = handleDblClick;
bIsIE = false;
}
ondblclick events? It is a difference in how they implement the Document Object Model. Internet Explorer handles double-clicks at the document level, hence document.ondblclick and everyone else (well, everyone else according to this code) uses the window object, so window.ondblclick. In both cases when there is a double-click the variable bDoubleClickHappenedhttp://mappinghacks.com/projects/gmaps/clicktoroute.html. You click on the map to create a continuous track. An example is shown in Figure 2-9.
38.4047068183193, -122.84743666648865 38.4041771393969, -122.84764051437378 38.403941725296505, -122.84796237945557
<?xml version="1.0"?> <gpx> <trk><name>Google Maps Hacks is Good</name> <trkseg> <trkpt lat="38.41324840580697" lon="-122.84113883972168"></trkpt> <trkpt lat="38.402688973080245" lon="-122.82877922058105"></trkpt> <trkpt lat="38.4049085997449" lon="-122.84637451171875"></trkpt> </trkseg> </trk> </gpx>
gpsbabel -r -i gpx -f route.gpx \ -x simplify,count=30 -o gpx \ -F shorter_route.gpx
http://www.vestaldesign.com/maps/starwars.html.
http://www.gimp.org/.http://igargoyle.com/slideshow.html.
http://boneill.ninjagrapefruit.com/wp-content/bbc/newmaps/ you can see the locations associated with the last 12 hours of BBC news, as shown in Figure 3-1. As with most cartographic efforts, there is the nearly inevitable, but still regrettable, focus on just one place—so the last 12 hours of BBC news will generally be more interesting if you prefer news of the British Isles.http://backstage.bbc.co.uk/ for data and ideas so that you can "build what you want using BBC content." This is the heart of the Web 2.0 concept—the idea that open APIs and open formats allow us to make more use of and draw richer connections between the vast amounts of information that are already out there on the Internet.
http://www.guardian.co.uk/online/story/0,,1522351,00.html.http://www.chicagocrime.org/), one of the original Google Maps hacks, is a freely browsable database of crimes reported in Chicago. It combines data that was screen scraped from the Chicago Police Department's Web site (http://12.17.79.6/) with Google Maps, enabling many new ways for Chicago residents to keep tabs on their neighborhoods and explore crimes reported throughout their city. The site lets you browse crime reports in many ways: crime type, street name, date, police district/beat, ZIP Code, city ward, and generic "location" (e.g., bowling alley, bar, gas station). Figure 3-3 shows a rash of peeping toms around residential Chicago, while Figure 3-4 shows the locations for bogus check reports. There's also a City map page at http://www.chicagocrime.org/map/ that lets you combine search criteria.
http://www.chicagocrime.org/districts/http://www.weatherbonk.com/, collects meteorological data aggregated by Weather Underground and Weatherbug from thousands of personal weather stations across the world, and then plots that information in a rich Google Maps interface on the Web.33010;33446 will give you points along the southeast coast of Florida.http://www.stormreportmap.com/, as shown in Figure 3-7.
http://spc.noaa.gov/. One of the top products that the SPC maintains is their Storm Report tracker at http://spc.noaa.gov/climo/. This product takes reports from trained weather spotters, emergency and first responders, and local residents, and then maps them to an unattractive, static page. Moreover, the reports also don't give much in the way of comprehensible locations, aside from latitude/longitude coordinates, and the county and state where the storm was reported. Additionally, since each report is submitted into the database as a separate event, there are times when several tornado reports received are actually all from the same tornado. Due to these shortcomings in the original product, and because of its general popularity, I felt that my project might enhance the product's basic functionality.http://gmaps.tommangan.us/spacecraft_tracking.html.http://en.wikipedia.org/wiki/International_Space_Station), the characteristic sine wave shape of low Earth orbits appears. No, objects in space don't bounce around like tennis balls; this represents the effects of representing a three dimensional orbit onto a flat map. The first rule of cartography is that you always distort something!
autoUpdate( ) function. autoUpdate( ) is called as soon as the page loads.<body style="background-color: #000; text-align: center;" onload="autoUpdate();">
autoUpdate function uses the GXmlHttp class from Google Maps to fetch the iss.js file from the server. You can take a look at the file at http://gmaps.tommangan.us/iss.js.-48.6;-11.7;369.8;-51.6;-31.9;291.1
http://meyerweb.com/eric/tools/gmap/hydesim.html. Figure 3-12 shows the default view, which illustrates the effect of a 150 kiloton explosion at ground level in downtown Manhattan.
http://nuclearweaponarchive.org/Nwfaq/Nfaq5.html.|
Overpressure
|
Structural effects
|
Human injuries
|
|---|---|---|
|
1 psi
|
Window glass shatters.
|
Light injuries from fragments occur.
|
|
3 psi
|
Residential structures collapse.
|
http://housingmaps.com/, shows a Google Maps view of the United States and Canada, as seen in Figure 3-13. The green icons on the map mark many of the major urban areas served by Craigslist, and clicking one opens a call-out, from which you can select real estate for sale, rentals, rooms for rent, and sublets or temporary housing for that city.
http://mapbureau.com/evmapper/. Figure 3-15 is a screenshot of the results of the "pug meetup" search.
http://evdb.com) is the Events and Venues Database, a free site that allows anyone to submit or search for events. An EVDB search displays a list of events; events can also be organized into personal calendars. However, maps are not currently part of the experience at the EVDB site.http://api.evdb.com). When a user enters a query into EVMapper, an /events/search call is made to the API; for example:http://api.evdb.com/rest/events/search?app_key=…&keywords=pug+meetup
http://greasemonkey.mozdev.org/, if you haven't done this already; see "Add Google Maps to Any Web Site"
[Hack #27]
for more information on how this works. To install the UPS tracking user script, visit http://www.thrall.net/~mking/maps/upstrack.user.js in Firefox, and then select Tools → Install User Script from the menu bar. A confirmation window will pop up, in which you can simply click OK.http://www.ups.com/content/us/en/index.jsx, enter a tracking number, click the checkbox to accept the terms and conditions of use, and then click the button marked Track. A summary page will load, with a "View package progress" link. Click this link as well. You should get a results page that looks something like Figure 3-16. This particular example shows the course of a box of O'Reilly's http://www.parsec.it/whereis/ knows where Internet addresses are hosted in the real world, sometimes with astonishing accuracy. The front page of the site, clearly modeled after Google's, offers a simple search box, where you can type in an Internet domain name or an IP address in dotted-quad format (e.g., 192.168.1.1). Clicking the locate button takes you to the view shown in Figure 3-18, with a Google Map showing a marker over the most probable physical location of that Internet address. Clicking on the marker pops up some basic information about the address, including the country and locale that it's believed to be physically located in or near.GMarker( ) constructor, which specifies the physical coordinates of the Internet address and generates the marker that you see on the map.http://www.oreilly.com/oreilly/contact.html and get the address, but what good does that do you? At the very least, you'll have to copy the address to your clipboard, and then go to http://maps.google.com/ in another browser window, paste the address in there, and so on. Isn't there some way your web browser could just do this for you?http://greasemonkey.mozdev.org/). When you first try to install Greasemonkey, you may see a thin bar at the top of Firefox that says "Firefox prevented an extension from loading." Click the button at the right side of that bar, then "Allow extensions from that site." Once you've done this, try installing Greasemonkey again; it should work the second time around.…when the Amazon shrank a record 11,200 square miles, an area roughly the size of Belgium, or the American state of Massachusetts….
"Huge iceberg menaces Antarctica…roughly the size of the island of Jamaica." (http://www.theregister.co.uk/2005/05/20/iceberg_penguin_menace/)"The largest-known iceberg was from this region. It was roughly the size of the state of Rhode Island." (http://www.factmonster.com/ipka/A0781668.html)"Months later, after I discussed what I had seen with the oceanographer Curtis Ebbesmeyer, perhaps the world's leading expert on flotsam, he began referring to the area as the 'Eastern garbage patch.' But 'patch.' doesn't begin to convey the reality. Ebbesmeyer has estimated that the area, nearly covered with floating plastic debris, is roughly the size of Texas." (http://www.naturalhistorymag.com/1103/1103_feature.html)
http://www.mappinghacks.com/projects/gmaps/size_of.html you can select the outline of a state or country and pin it onto the map. Pick the shape from a drop-down box then scroll around on the map until you find a familiar place and click. Figure 3-25 shows an outline of Pennsylvania on top of Hungary.http://www.ahding.com/cheapgas/,I also know where the cheap gas flows.http://www.gasbuddy.com/, which aggregates user reports of gas prices so that everyone can benefit. You can also contribute to the Gas Buddy web site by becoming one of their volunteer spotters, thus gratifying your natural human desire to tell other people something that they don't know.
http://www.gasbuddy.com/. GasBuddy.com provides the database of cheap gas, but is not run by cartographers, so Ahding.com was able to create the now-classic mashup.http://www.ahding.com/cheapgas/,I also know where the cheap gas flows.http://www.gasbuddy.com/, which aggregates user reports of gas prices so that everyone can benefit. You can also contribute to the Gas Buddy web site by becoming one of their volunteer spotters, thus gratifying your natural human desire to tell other people something that they don't know.
http://www.gasbuddy.com/. GasBuddy.com provides the database of cheap gas, but is not run by cartographers, so Ahding.com was able to create the now-classic mashup.http://www.ahding.com/movie/ and use the same basic interface to query the Internet Movie Database (http://www.imdb.com) to check out local movies.http://www.widgetgallery.com/view.php?widget=36500. This is a widget that will run under Konfabulator for Windows and Mac OS X (the grass is greener on both sides) and show you the best prices for gas. "GasWatch shows you the lowest priced gas in your ZIP Code. It also provides a handy button to show a map to the gas station. Maps for Mac users provided by Google Maps."http://supergreg.hopto.org/google-traffic.com/. Using RSS from the Traffic.com web site, "Super" Greg Sadetsky has assembled an informative service that reports the locations of traffic conditions in major U.S. cities. From the front page, you can select your city of interest, and click the Go! button to be taken directly to the map. Figure 4-3 shows the current traffic conditions in Philadelphia.
http://www.david.enigmati.ca/maps/transit.html. As you can see from Figure 4-9, the site uses Google Maps polylines to depict the major transit routes in town.
http://www.thrall.net/maps/mbta.html takes something of a similar approach, as you can see in Figure 4-10. Instead of the station labels on the map, along the top we get a row of color-coded drop-down boxes, organized by subway line, to help find individual stations.http://google.com, the first link is to the Google Phonebook (assuming that the number is found). For example, doing a search on the U.S. phone number (707) 827-7000 brings up the results shown in Figure 4-13. The Google phone book is very forgiving. You can search for 707 827-7000 or 707-827-7000 or even 7078277000 and Phonebook will still work.
sll parameter, which stands for search lat/long. Look at the address bar in Figure 4-14, and you can see the URL query string ?q=pizza&sll=38.411170,-122.841720. So, phone number (707) 827-7000 is located at 38.411170 N, 122.841720 W. That location isn't perfect, but it is pretty darn good. See "Inside Google Maps URLs"
[Hack #7]
for more on the structure of Google Maps URLs.
http://www.cellreception.com/towers/index.html and browse for cell towers by city or state. When I look up Sebastopol, California, I get the map in Figure 4-15.
var html="<h1><a href='http://www.cellreception.com/towers/details.php?id=" + id + "'>" + name + "</a></h1><br>" + address + "<br>" + city + ", " + state;
The FCC does not require every antenna structure to be registered, and the map may not list all the towers in the area. Additionally, many carriers have sold their tower assets to third party companies, and leasing agreements are unknown. If this is the case, the best way to determine carrier coverage is by reading comments in the local area.
http://BayAreaHikingTrails.ning.com, looks like Figure 4-17.
http://www.gpsbabel.org) makes it possible to convert driving directions from Google Maps into various formats usable by other software and devices. This is possible because Google encodes the coordinates of the entire route in the JavaScript that is sent to the Google Maps client and used to generate the route that is put on the map.
&output=js to the end of the URL in your address bar and hit Enter. Your URL will look like this (but all on one line):http://maps.google.com/maps?q=jfk+to+350+5th+ave,+new+york&spn =0.103861,0.199934&hl=en&output=js
&output=js, and instead just enter the URL of the JavaScript page straight into your browser. Here is a link to the page containing the points for directions from JFK to San Francisco International Airport the hard way:38, -121 to 39.526421, -119.807539 are shown in Figure 4-19.
38, -121 to 39.731482, -119.53537, you get "We could not calculate driving directions between 38, -121 and 39.731482, -119.53537." Since 38, -121 worked in the first example, Google must have a problem with 39.731482, -119.53537. A glance at Figure 4-20 shows that Google should be forgiven for this routing difficulty. Apparently the engineers didn't anticipate helicopter-based mountain-top expeditions.SFO to DEN, using an airport-to-airport search. Why do you need more than one set of directions?
http://www.tom-carden.co.uk/googlegpx/ and upload your own GPX format file. Any waypoints appear as marker pins, and the start and end of tracks will be marked with pins, as shown in Figure 4-23.
iframe element and new friends like XMLHttpRequest can help us here.http://WiFiMaps.com.http://www.netstumbler.com, which is popular among wardrivers. For free 'nix operating systems, Kismet (http://www.kismetwireless.net/) is the tool of choice, while on Mac OS X, there's both MacStumbler (http://www.macstumbler.com/) and KisMAC (http://kismac.binaervarianz.dehttp://earth.google.com/. Tragically, although it's based on the OpenGL standard, Google Earth is, as of this writing, supported on Windows only.http://www.openstreetmap.org/).http://labs.google.com/ridefinder. The initial view shown in Figure 4-26 is of North America, with push pins marking the areas for which they have data.
http://labs.google.com/ridefinder/data?file=ride_js, referenced from the HTML source. The Update Vehicle Locations button calls refreshMarkers(), which then calls updateMarkers(). This function constructs the following URL:var j="/ridefinder/data?marker=1&lat="+f+"&lon="+g+"&z="+m+ "&src="+w+"¬es="+(new Date()).getTime();
f and g are the lat/long center of the map, m is the zoom level, and w is hardcoded to 3. The notes argument is a timestamp, which seems to be appended to avoid hitting any cache. Constructing a URL with, for example, the center of Manhattan and scale 8, confirms that this is the feed for Ride Finder.
http://www.kokogiak.com/webtools/greasemonkey/a9imagesingooglemaps.html. From that page, right-click on the link to a9gmap.user.js and select Install User Script. An installation window will pop up, as depicted in Figure 5-14.http://anti-mega.com/flickrcity/), anyone can do this easily.http://www.geobloggers.com/) were using Flickr as a data source and had already created a standard for geotagging photos.http://anti-mega.com/flickrcity/helsinki.city, as shown in Figure 5-15.
http://anti-mega.com/flickrcity/helsinki.city?tags=food. Figure 5-16 shows what this looks like.http://anti-mega.com/flickrcity/helsinki.city?user=chrisdodo, as Figure 5-17 demonstrates.http://anti-mega.com/flickrcity/helsinki.city?tags=food&user=chrisdodo.geotagged, which allows us to find them using the Flickr API. Second, they have the tags geo:lat=…and geo:long=…associated with them, which gives us their geographic coordinates. Figure 5-18 shows one sort of map that can be made by mashing up the Flicker API and the Google Maps API.http://www.flickr.com/services/api/. Once you have a key, you can query Flickr using the flickr.photos.search call from their REST API, with a URL like:
http://www.flickr.com/services/rest/?method=flickr.photos.search&api_
key=[your API key]&tag_mode=all&tags=geotagged&per_page=20
<?xml version="1.0" encoding="utf-8" ?> <rsp stat="ok"> <photos page="1" pages="8553" perpage="5" total="42761"> <photo id="30221122" owner="47836075@N00" secret="11f6695a02" server="21" title="From Camera Server(SlabbersCam)0000/00/06,15:00:07" ispublic="1" isfriend="0" isfamily="0" /> <photo id="30218138" owner="78211664@N00" secret="5a36fff7b3" server="21" title="P8010502" ispublic="1" isfriend="1" isfamily="1" /> <photo id="30218130" owner="78211664@N00" secret="8bda841d8b" server="23" title="P8010498" ispublic="1" isfriend="1" isfamily="1" />
http://www.geobloggers.com) to aggregate the geotagged photos.geo: lat=xx.xxxx, geo.lon=yy.yyyy, and geotagged.geotagged tag is necessary to let you search for geotagged photos. There are two ways to geotag photos: manually and using Google Maps.
http://www.fcc.gov/mb/audio/bickel/DDDMMSS-decimal.html.geo:lat=71.171067 geo:lon=25.783050 geotagged
http://www.mozilla.org/products/firefox/http://www.communitywalk.com/) attempts to facilitate the process of placing photos on a map showing where they were taken. The intent of it was, surprisingly enough, not to simply alleviate the boredom of vacation slideshows, but rather to allow people to share their communities. I roughly define a community as a group of things that share some commonality in the mind of some person or group of people. Although a community does not necessarily have to exist in a physical area, it does have to involve something that exists in a physical location, even if that is just the people that are involved in the community.GMap object in memory, which is the key to the Google Maps object structure. Every page that shows a Google Map (under the official API) must have a line that looks like this:
var map = new GMap(document.getElementById("map"));
GMap object is a global variable. If the page creates the GMap object within a function, the bookmark will fail. User-created global variables and methods can be accessed by iterating through the global object this. Without a JavaScript function to query an object for its user created class, the bookmarklet calls getCenterLatLng( ) on each global object within a try/catch block. If this call does not generate an error, the GMap object has been found and things can move forward. The other assumption is that overlays are GMarker objects that respond to click events by calling openInfoWindowHtml(). This is probably the most common way of constructing a Google Map.http://www.mattkruse.com/JavaScript/datadumper/, can be very useful to investigate the structure of the GMap object and find the overlays, without following through the API's obfuscated code. We can start by creating a basic Google Map with overlays and info windows, according to the documentation. Next, we load in http://www.thingster.org/, and it is open source and open data licensed as well. You're welcome to log in, create an account, and play with it; you're also welcome to run your own copy or just take any ideas you like and build your own equivalent.head section of your page. If your map div is named something other than map, you'll need to replace #map with the appropriate name (e.g., #mymap).
<style type="text/css">
html, body, #map {
width: 100%;
height: 100%;
}
html {
overflow: hidden;
}
body {
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
}
</style>
head section of your page. If your map div is named something other than map, you'll need to replace #map with the appropriate name (e.g., #mymap).
<style type="text/css">
html, body, #map {
width: 100%;
height: 100%;
}
html {
overflow: hidden;
}
body {
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
}
</style>
width and height declarations cause the map container to fill the entire document body, and the body to take up all the available window space. Make sure you don't have any inline width or height attributes on your map element that could override these. The overflow:hidden line hides any scrollbars the browser would otherwise display, and the margin and padding lines get rid of the white border that is shown by default around a document. This leaves us with a map container that stretches to fit all the available window space in the browser (minus that reserved for the toolbars, status bar, etc.).http://mappinghacks.com/projects/gmaps/map_in_box.html and shown in Figure 6-4.
openInfoWindow(), openInfoWindowHtml( ), and openInfoWindowXslt( ). The second type is really just a single method that takes no HTML as input and produces a blow-up map of some point inside of the info window, but nothing else. This method is showMapBlowup().showMapBlowup() method, namely showMapBlowup(point, zoomLevel?, mapType?, pixelOffset?, onOpenFn?, onCloseFn?), we see there is no way to insert text into a map blowup. How do we get a map and text into an info window?openInfoWindowHtml( ), we see that it has the prototype openInfoWindowHtml(marker, htmlStr, pixelOffset?, onOpenFn?, onCloseFn?), where htmlStr is any string of HTML. Well, since we are using a div element to create the main map, why not try putting a div element into the htmlStr? As it turns out, that works almost wonderfully:
GEvent.addListener(testmarker, "click", function ( ) {
var text = '<p style="text-align: left">';
text += '<div id="minimap" style="width: 200px; height: 200px"></div>';
text += 'Here is some text.<br>';
text += 'This is a link to <a href=
"http://maps.google.com/">Google Maps</a>';
testmarker.openInfoWindowHtml(text);
var minimap = new GMap(document.getElementById(minimap));
minimap.centerAndZoom(pt,1);
minimap.addControl(new GSmallMapControl( ));
});
map.addOverlay(testmarker);
openInfoWindowHtml( ) method of the GMarker class to add the required HTML to our document. The string we'll be passing is stored in a variable called flashHtml.flashHtml = '<object classid="clsid:d27cdb6e-ae6d-' + '11cf-96b8-444553540000" ' + 'codebase="http://fpdownload.macromedia.com/pub/' + 'shockwave/cabs/flash/swflash.cab#version=7,0,0,0" ' + 'width="128" height="53" id="FlashBit" align="middle">' + '<param name="allowScriptAccess" value="sameDomain" />' + '<param name="movie" value="FlashBit.swf" />' + '<param name="quality" value="high" />' + '<param name="bgcolor" value="#ffffff" />' + '<param name="wmode" value="transparent" />' + '<embed src="FlashBit.swf" quality="high" ' + 'bgcolor="#ffffff" width="128" height="53" ' + 'name="FlashBit" align="middle" ' + 'allowScriptAccess="sameDomain" ' + 'type="application/x-shockwave-flash" ' + 'wmode="transparent" ' + 'pluginspage="http://www.macromedia.com/go' + '/getflashplayer" />' + '</object></center>';
object tag is used by Internet Explorer on Windows platforms, while Netscape and Internet Explorer for the Mac both use the embed tag instead. More information on why you need both tags can be found in Macromedia's knowledge base at http://gmaps.tommangan.us/tlabel.html, with a Google satellite image of two U.S.
http://gmaps.tommangan.us/tlabel.html. There is a link to a JavaScript file, currently http://gmaps.tommangan.us/tlabel.19.js, but check for the current version. Copy that file onto your own server and include it after you include the Google Maps API.
<script src="http://maps.google.com/maps?file=api&v=1&key
=AOJVHiMoLlyAv…x3sA" type="text/javascript"></script>
<script src="tlabel.10.js" type="text/javascript"></script>
http://mappinghacks.com/projects/gmaps/brc_tlabel.html. Here is code to create a label, as shown in Figure 6-9:var label = new TLabel(); label.id = 'mail_box'; label.anchorLatLng = new GPoint (-119.226396, 40.768080); label.anchorPoint = 'bottomLeft'; label.content = 'Mail Box'; label.percentOpacity = 85; map.addTLabel(label);
http://gmaps.tommangan.us/groom_lake.html. Figure 6-11 shows a 1968 image over the Google Satellite imagery.http://gmaps.tommangan.us/tphoto.html/. The current version is tphoto.16.js, available at http://gmaps.tommangan.us/tphoto.16.js. Place it on your server and include it after you include the Google Maps API in your JavaScript. You could include it directly from the tommangan.us server, but it is on very rare occasions not available, so I recommend you download the file to your own server and link it as shown here:<script src="http://maps.google.com/maps?file=api&v=1&key=ApAUl_iS-dEaDI.RA" type="text/javascript"></script> <script src="tphoto.16.js" type="text/javascript"></script>
var groom1959 = new TPhoto(); groom1959.id = 'groom1959'; groom1959.src = 'images/groom1959.jpg'; photo.percentOpacity = 50; groom1959.anchorTopLeft = new GPoint(-115.823107,37.248368); groom1959.anchorBottomRight = new GPoint(-115.801649,37.230123); map.addTPhoto(photo);
http://www.mappinghacks.com/projects/gmaps/brc_ref.html you see the Google aerial photo of the site of the Burning Man festival in the Black Rock desert of Nevada. If you click "show plan," you'll get the 2005 Burning Man city plan overlaid on the Google Map as shown in Figure 6-14.
<script src="GxMagnifier.1.js" type="text/javascript"></script>
map.addControl(new GxMagnifierControl());
map.addControl API call. This is all you need to do to get the basic magnifier control. This is only the most basic example of what GxMagnifier can do! The full documentation, with complete reference to the API can be found here: http://www.googlemappers.com/libraries/gxmagnifier/docs/default.htm.GxMagnifierControl object within our map.addControl() call:map.addControl(new GxMagnifierControl());
GxMagnifierControl later on. GxMagnifier can do more for us! The next examples will start with this basic framework, with the crucial lines highlighted. Of course, you'll need to use your own developer's key.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/ TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>GxMagnifier Example Framework</title> <script src="http://maps.google.com/ maps?file=api&v=1&key=ilovemykidsmandms" type="text/javascript"></script>
centerAndZoom( ) method that accepts a center point of the map, expressed as a latitude and longitude pair, and a zoom level. Google documents the zoom level as an integer, and the examples in their documentation all use 4 as the zoom level, but no definition of the zoom levels themselves is given. Experimentation shows that they correspond with the ticks on the zoom level control.
function computeZoom(minX, minY, maxX, maxY) {
var zl;
var bounds = map.getBoundsLatLng();
var cz = map.getZoomLevel();
var mapWidth = Math.abs(bounds.maxX - bounds.minX);
var mapHeight = Math.abs(bounds.maxY - bounds.minY);
var myWidth = Math.abs(maxX - minX);
var myHeight = Math.abs(maxY – minY);
var changeZoom = myWidth > mapWidth ? 1 : -1;
// Just rip through until we find the lowest that will hold our span.
// For certain geometries (around hemisphere boundaries), this won't work
for(zl=map.getZoomLeve( );zl> 2&&zl<17; zl += changeZoom) {
width = width * Math.pow(2, changeZoom);
height = height * Math.pow(2, changeZoom);
if ((width < lon) || (height < lat))
return zl - 1;
}
return zl;
}
GMap object becomes really noticable. The inclination is to want to show markers as quickly as possible, so that the user gets immediate feedback on what's going on, but it's been discovered that if you buffer the objects and then manually trigger the redraw, it is much faster.addOverlays( ). By assigning it to the GMap class prototype, it becomes available on any GMap objects we create. The code looks like this:
// This is a bit of a trick for the 1.0 API. The 'addoverlay' method
// is agonizingly slow, so we buffer up the markers in the 'overlays'
// array and then deliver them to GMAP in one shot.
GMap.prototype.addOverlays=function(a) {
var b=this;
for (i=0;i<a.length;i++) {
try {
this.overlays.push(a[i]);
a[i].initialize(this);
a[i].redraw(true);
} catch(ex) {
alert('err: ' + i + ', ' + ex.toString());
}
}
this.reOrderOverlays();
}
addOverlays() method can be used directly in your code or included via a script element in your HTML, after you include the Google Maps library.map.addOverlay( ) for each marker or polyline we create, we'll push each overlay onto an array, and then pass the array to map.addOverlays( ). Here's a fragment of a simple GPX reader that displays waypoint data using this idea:
var wpts = GPX.documentElement.getElementsByTagName("wpt");
var markers = [];
for (var k = 0; k < wpts.length; k++) {
var point = new GPoint(trkPts[k].getAttribute("lon"),
trkPts[k].getAttribute("lat")));
var marker = new Gmarker(point);
// … we could do things with the marker here,
// like set a custom icon or configure an info window …
http://jamesedmunds.com/poorclio/googlemap11.cfm offers a terrific example of how Google Maps hacks can respond to user actions. The site, built by James Edmunds, shows two Google Maps of the same location side by side. On the left, the regular map mode is shown, while the map on the right shows the same map in satellite mode. Figure 6-20 shows the side-by-side view of the area around 30th Street Station in Philadelphia, with the rail yards extending away to the north.
GEvent.addListener(marker, "click", function( ) {
marker.openInfoWindowHtml(html);
});
GEvent class to register a click event on a marker object. When the marker is clicked, the anonymous function gets called, and the info window is opened. As it happens, the Google Maps API offers several other events for tracking and responding to user interactions.http://geocoder.us, but the DNS for the Geocoder site, like that of many sites, is configured to treat http://www.geocoder.us/ as a synonym for http://geocoder.us/. The two domains resolve to the same server, which means that the same page will be served up to people asking for either domain. This works fine, until you put the Google Maps API key into the mix.http://www.google.com/apis/maps/." One can be forgiven the odd chuckle at the irony of http://maps.google.com/apis/maps/, as shown in Figure 6-21.
<script
src="http://maps.google.com/maps?file=api&v=1&key=yourkeyhere"
type="text/javascript">
</script>
script element, it attempts to load the script specified in the URL listed in the src attribute. When a browser asks for information from a web server, it also sends information, including the name of the server and the page that referred the user to get the script. Google Maps is probably using the HTTP referer that is automatically sent to the server by your browser.http://www.census.gov/geo/www/tiger/. As of 2004, updated versions are published twice a year.http://www.map-server.com/googlemaps/subfinder.php, is integrated with a MySQL database using PHP. The Subfinder is itself an extension of the Who Locations site at http://www.map-server.com/googlemaps/wholocations2.php, which is described in a tutorial at http://www.map-server.com/googlemaps/tutorial.html. Figure 7-2 shows a map of the sites that any fan of The Who must know about.lat, long, and description columns.
CREATE TABLE subfinder ( id int(11) NOT NULL auto_increment, lat decimal(10,6) NOT NULL default '0.000000', lon decimal(10,6) NOT NULL default '0.000000', desc varchar(255) NOT NULL default '', url varchar(255) NOT NULL default '', marker char(1) NOT NULL default '', PRIMARY KEY (id) ) TYPE=MyISAM;
$ mysqladmin create sub_db
$ mysql sub_db < create_subfinder.sql
XIcon and XMarker classes from XMaps. The XMaps library lives on the Web at http://xmaps.busmonster.com/.XIcon class is similar to Google's GIcon class, but it automates some of the steps necessary to create icons, making it simpler to make new icons on the fly. You could do the same thing that the XIcon class does by using a server-side script, but here we are using something that does not require any extra server horsepower or bandwidth from you. XIcon objects are limited in that they are a filled concave polygon (e.g., the outline of a car, lion, or circle), but you have the advantage of being able to specify the color, size, opacity, and any text on it on the fly.GIcon class makes use of a set of pre-rendered PNG images stored on a server somewhere. The default GIcon uses three images from Google Ride Finder to create its resulting image: the reddish-orange marker image, a nearly transparent version of that same image (for click detection on IE), and a mostly transparent shadow image. Figure 7-3 shows the parts of this pre-rendered icon.
XIcon's images are created on the fly by using the existing (but unofficial) service that Google Maps already uses to draw polylines. Using this service, we can actually draw images of any color and opacity. By specifying the outline of the icon shape, the XIcon class can create the necessary images for you (including the shadow image). For example, if we wanted to create a rounded box icon, we could come up with a list of points for the outline, give them to http://wms.jpl.nasa.gov/wms.cgi?request=GetMap&layers =global_mosaic_base&srs=EPSG:4326&bbox=-87.90,24.38,-76.65,30.01 &FORMAT=image/png&width=600&height=400&styles=pseudo
bbox (or bounding box) that covers the area from 87.9 W to 76.65 W and 24.38 N to 30.01 N, which happens to be most of Florida.http://www.onnyturf.com/subwaymap.php), I felt that Google's polylines were not elegant enough, and they were hard to see on top of Google's orange/green default map. To make the subway lines easier to see against the streetscape and to make the lines look nicer, I decided to add a custom map type that I illustrated, as you can see from Figure 7-14.http://www.kokogiak.com/gmaps-transparencies.html. You will need to know these basics on adding a custom map in order to add transparency in that way.
<?php
define("NO_DATA", "./no_data.gif");
define("ZOOM_IN", "./zoom_in.gif");
define("ZOOM_OUT", "./zoom_out.gif");
$x = $_GET["x"];
$y = $_GET["y"];
$z = $_GET["zoom"];
$filename = "./nycmaps/${x}_${y}_${z}.gif";
if ( $z < 2 ) {
$content = file_get_contents( ZOOM_OUT );
}else if ( $z > 5 ){
$content = file_get_contents( ZOOM_IN );
}else if ( is_numeric($x) && is_numeric($y) && is_numeric($z)
&& file_exists( $filename ) ){
$content = file_get_contents( $filename );
}else{
$content = file_get_contents( NO_DATA );
}
header("Content-type: image/gif");
echo $content;
?>
x, y, and zoom values.
http://mt.google.com/mt?v=w2.4&x=1206&y=1539&zoom=5
x, y, and z values for all your images. We only need to get a set of values for one tile and from there we can derive all the other values we need.x, y, and z value of the upper-left corner tile of our map area and know how many tiles wide and high our map area is. For simplicity, our example map is square so that the area width and height are the same, but you could tweak this script to work with rectangular areas. Once we know the upper-left corner tile values, our batch processing script will calculate the rest for us.http://mappinghacks.com/projects/gmaps/cluster.html, as shown in Figure 7-27. The standard Google Maps marker is used to represent a cluster of points, roughly bounded by the red box around the marker. Clicking on a marker pans and zooms the map to the area covered by that cluster. As you get closer in, more localized clusters appear, eventually resolving into the small Google Ridefinder markers, which represent Rich's individual waypoints. Clicking on one of these smaller markers opens a small info window, showing the name and coordinates of the waypoint, as shown in Figure 7-28 .Detour Index = road distance ÷ straight line distance X 100
http://mappinghacks.com/projects/gmaps/lines.html. Be careful to measure the same distance! I noted the start and stop points of the Google route and tried to match those in calculating the straight-line distance as shown in Figure 7-31.
68.1÷55.1 X 100=123.6.Return to Google Maps Hacks