Welcome to Instant HTML5 Geolocation How-to. This guide will help you make any web application aware of a user's location, quickly and easily. You will learn how to map a user's geographic location, integrate with popular mapping platforms, and track the user over time. In the process, you will create a simple application that generates a KML file containing both a path and points that you choose to save along that path (which can then be imported into Google Maps).
The iPhone changed the way we use the web. It was the first mobile device that included web browsing as a primary function. Suddenly, with mobile data and a phone like the iPhone, the web could be in your pocket, wherever you went. Through HTML5 and APIs, web applications could be truly context sensitive; they could know where you were, if you wanted them to, and react accordingly.
Setting up the application (Simple) explains how to configure and set up a sample application layout suitable for running a simple Geolocation-aware web application. Each step is explained in a way that will help you understand how your data will be stored so that you can scale your application when you're ready.
Getting the user's location (Intermidiate) illustrates how to detect Geolocation support in the user's web browser, use the API to obtain the user's coordinates, and handle any errors that might occur.
Displaying the user's location using the Google Maps API (Intermidiate) discusses how to display the coordinates obtained in the previous section in a visual way using Google Maps.
Displaying the user's location using a KML feed (Intermidiate) explains how to create the KML feed from coordinates you have saved in previous sections, and test it by importing it into Google Maps. KML feeds are supported by popular mapping applications such as Google Maps and Google Earth, as well as specialist GIS software.
Tracking and updating the user's location (Intermidiate) illustrates how to track the user and show his/her path, using simple web technologies. Sometimes, tracking the user's movements is important. Here we will use
clearPosition() to track the user's location over time, and change the maps that were created in the previous section.
You need to have access to a server or computer running Apache Web Server, MySQL, and PHP. You will also need a text editor, a recent version of a major web browser, and optionally, a web-capable mobile device with GPS support.
In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.
Code words in text are shown as follows: "In this section, we will be concentrating on
A block of code is set as follows:
[<?php $server = ''; // Enter your database server here $username = ''; // Enter your database username here $password = ''; // Enter your database password here $database = ''; // Enter your database name here // Connect to the database
New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Select File | Save in your web browser while viewing the feed."
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send us general feedback, simply send an e-mail to
<[email protected]>, and mention the book title via the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at
<[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors, and our ability to bring you valuable content.
You can contact us at
<[email protected]> if you are having a problem with any aspect of the book, and we will do our best to address it.