L'autore:
Mike Purvis is a Engineering student at the University of Waterloo. He maintains a weblog at uwmike.com and enjoys cooking, cycling, and playing with LEGO. He's worked on many web projects of various sizes and has a strong interest in independent standards and open source. Jeff Sambells is a Graphic Designer and self taught Web Application developer best known for his unique ability to merge the visual world of graphics with the mental realm of code. With a Bachelor of Technology degree in Graphic Communications Management and a minor in Multimedia, Jeffrey was originally trained for the paper and ink printing industry, but he soon realized the world of pixels and digital ink was were his ideas would prosper. In late 1999, he co-founded We-Create Inc. an internet software company based in Waterloo, Ontario, which began many long nights of challenging and creative innovation. Currently, as Director of Research and Development for We-Create, Jeffrey is responsible for investigating new and emerging internet technologies and integrating them using web standards compliant methods. He is described by his peers as both a natural programmer and an innovative thinker. Cameron Turner has been programming interactive games since his first computer in 1985; interactive web sites since 1994 and since 1999 has been one of the founders of We-Create Inc. He obtained his honours degree in Computer Science from the University of Waterloo Ontario, with specializations in applied cryptography, database design and computer security. As the Chief Technology Officer at We-Create Inc. Cam has been involved in all aspects of Internet software development, design and specification. More than a manager, Cam maintains an active ability to develop in all of the latest break-through technologies as well as an ability to easily translate tech-talk into lay-English for clients and their stakeholders.
Contenuti:
Beginning Google Maps
Applications with
PHP and Ajax
From Novice to Professional
Michael Purvis
Jeffrey Sambells
and Cameron Turner
Beginning Google Maps Applications with PHP and Ajax: From Novice to Professional
Copyright © 2006 by Michael Purvis, Jeffrey Sambells, and Cameron Turner
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means,
electronic or mechanical, including photocopying, recording, or by any information storage or retrieval
system, without the prior written permission of the copyright owner and the publisher.
ISBN-13 (pbk): 978-1-59059-707-1
ISBN-10 (pbk): 1-59059-707-9
Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1
Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence
of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark
owner, with no intention of infringement of the trademark.
Lead Editor: Jason Gilmore
Technical Reviewer: Terrill Dent
Editorial Board: Steve Anglin, Ewan Buckingham, Gary Cornell, Jason Gilmore, Jonathan Gennick,
Jonathan Hassell, James Huddleston, Chris Mills, Matthew Moodie, Dominic Shakeshaft, Jim Sumser,
Keir Thomas, Matt Wade
Project Manager: Elizabeth Seymour
Copy Edit Manager: Nicole LeClerc
Copy Editor: Marilyn Smith
Assistant Production Director: Kari Brooks-Copony
Production Editor: Katie Stence
Compositor: Kinetic Publishing Services, LLC
Proofreader: Liz Welch
Indexer: Beth Palmer
Cover Designer: Kurt Krames
Manufacturing Director: Tom Debolski
Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor,
New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail orders-ny@springer-sbm.com, or
visit http://www.springeronline.com.
For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley,
CA 94710. Phone 510-549-5930, fax 510-549-5939, e-mail info@apress.com, or visit http://www.apress.com.
The information in this book is distributed on an “as is” basis, without warranty. Although every precaution
has been taken in the preparation of this work, neither the author(s) nor Apress shall have any
liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly
or indirectly by the information contained in this work.
The source code for this book is available to readers at http://www.apress.com in the Source Code section
or at the official book site, http://googlemapsbook.com.
Contents
Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
About the Authors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
About the Technical Reviewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii
PART 1 ■ ■ ■ Your First Google Maps
■CHAPTER 1 Introducing Google Maps. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
KML: Your First Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Wayfaring: Your Second Map. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Adding the First Point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Adding the Flight Route . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Adding the Destination Point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Adding a Driving Route . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
What’s Next? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
■CHAPTER 2 Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
The First Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Keying Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Examining the Sample Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Specifying a New Location. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Separating Code from Content . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Cleaning Up. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Basic Interaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Using Map Control Widgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Creating Markers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Opening Info Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
A List of Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Using Arrays and Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Iterating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
vii
■CHAPTER 3 Interacting with the User and the Server. . . . . . . . . . . . . . . . . . 31
Going on a Treasure Hunt. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Creating the Map and Marking Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Starting the Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Listening to User Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Asking for More Information with an Info Window. . . . . . . . . . . . . . . . . . . . 37
Creating an Info Window on the Map . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Embedding a Form into the Info Window. . . . . . . . . . . . . . . . . . . . . . . 39
Avoiding an Ambiguous State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Controlling the Info Window Size. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Using Google’s Ajax Object. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Saving Data with GXmlHttp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Parsing the XML Document Using DOM Methods . . . . . . . . . . . . . . . 54
Retrieving Markers from the Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Adding Some Flair . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
■CHAPTER 4 Geocoding Addresses. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Creating an XML File with the Address Data. . . . . . . . . . . . . . . . . . . . . . . . . 63
Using Geocoding Web Services. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Requirements for Consuming Geocoding Services . . . . . . . . . . . . . . 66
The Google Maps API Geocoder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
The Yahoo Geocoding API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Geocoder.us . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Geocoder.ca . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Services for Geocoding Addresses Outside Google’s Coverage. . . . 85
Caching Lookups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Building a Store Location Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
PART 2 ■ ■ ■ Beyond the Basics
■CHAPTER 5 Manipulating Third-Party Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Using Downloadable Text Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Downloading the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Parsing CSV Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Optimizing the Import . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
Using Your New Database Schema. . . . . . . . . . . . . . . . . . . . . . . . . . . 106
■CONTENTS viii
Screen Scraping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
A Scraping Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
Screen Scraping Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
■CHAPTER 6 Improving the User Interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
CSS: A Touch of Style . . ...
Le informazioni nella sezione "Su questo libro" possono far riferimento a edizioni diverse di questo titolo.