Book Image

Google Maps JavaScript API Cookbook

Book Image

Google Maps JavaScript API Cookbook

Overview of this book

Day by day, the use of location data is becoming more and more popular, and Google is one of the main game changers in this area. The Google Maps JavaScript API is one of the most functional and robust mapping APIs used among Geo developers. With Google Maps, you can build location-based apps, maps for mobile apps, visualize geospatial data, and customize your own maps.Google Maps JavaScript API Cookbook is a practical, hands-on guide that provides you with a number of clear, step-by-step recipes that will help you to unleash the capabilities of the Google Maps JavaScript API in conjunction with open source or commercial GIS servers and services through a number of practical examples of real world scenarios. This book begins by covering the essentials of including simple maps for Web and mobile, adding vector and raster layers, styling your own base maps, creating your own controls and responding to events, and including your own events.You will learn how to integrate open source or commercial GIS servers and services including ArcGIS Server, GeoServer, CartoDB, Fusion Tables, and Google Maps Engine with the Google Maps JavaScript API. You will also extend the Google Maps JavaScript API to push its capabilities to the limit with additional libraries and services including geometry, AdSense, geocoding, directions, and StreetView.This book covers everything you need to know about creating a web map or GIS applications using the Google Maps JavaScript API on multiple platforms.
Table of Contents (15 chapters)
Google Maps JavaScript API Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

Currently, there are both open source and proprietary alternatives to the Google Maps JavaScript API, but what makes the API special for developers is that it is a complete solution with base maps, overlays, and technical capabilities.

The API has been especially exciting for developers because it is very easy to build up generic outcomes, and at the same time, it has its own tips and tricks and advanced functionalities within the same box. Therefore, you can swim afloat or dive deep when you are working with the API.

The Google Maps JavaScript API v3 enabled the quick and easy development of mobile scenarios, facilitating location-based solution developers to delve into the subject. Regarding the growth of mobile development, especially location-based applications, the Google Maps JavaScript API v3 has deserved rightful attention.

Last but not least, no mapping API has ever been as successful as the Google Maps API without the support of continuously updated and thoroughly handled vector and satellite data. Google has dedicated immense resources to maintaining the unified structure of the vector data and its cartographic quality, and this effort is paying off in terms of its API usage.

What this book covers

Chapter 1, Google Maps JavaScript API Basics, instructs you on how to create a simple Google Maps application centered around a main recipe. The map object and its primary options, including map types, will be introduced by adding details to the recipe.

Chapter 2, Adding Raster Layers, presents the addition of external raster data through a series of recipes alongside Google layers such as the Tile, Traffic, Transit, and Weather layers.

Chapter 3, Adding Vector Layers, introduces you to drawing vector features together with the display of external vector sources such as KML and GeoRSS.

Chapter 4, Working with Controls, explains controls in detail. Creating and customizing a custom user interface for both the Web and mobile will be introduced in this chapter.

Chapter 5, Understanding Google Maps JavaScript API Events, describes events in detail to react to map, layer, or marker's behaviors such as zoom end, layer changed, or marker added. Events will add more interactivity to mapping programming.

Chapter 6, Google Maps JavaScript Libraries, explains the libraries that will extend the capabilities of the Google Maps JavaScript API in detail. These libraries have different abilities to increase the power of the Google Maps JavaScript API.

Chapter 7, Working with Services, elaborates on services that will extend the Google Maps JavaScript API. These services, including Geocoding and Street View, expose the real power of mapping with the Google Maps JavaScript API.

Chapter 8, Mastering the Google Maps JavaScript API through Advanced Recipes, explains the integration of external GIS servers and services with the Google Maps JavaScript API. These includes ArcGIS Server, GeoServer, CartoDB, and Google Fusion Tables with OGC services such as WMS.

What you need for this book

The Google Maps JavaScript API works with HTML, CSS, and JavaScript code. So, a text editor with HTML, JavaScript, and CSS handling capabilities will be a good friend while exploring this book.

For Mac users, there are lots of commercial or free text editors, such as TextWrangler, BBEdit, Sublime Text, or WebStorm. They all handle HTML, JavaScript, and CSS beautifully.

For Windows users, there are different text editors as well, but Notepad++ is the most used and recommended one.

Choosing an editor depends on your computer's habits, so there is no exact solution or recommendation for users to select one editor. Everyone has a different perception that affects these choices.

There is also need for an HTTP server to implement these recipes. There are a bunch of HTTP servers including Apache, IIS, and so on. But the installation process of standalone servers can be a problem for most users. We encourage you to use solutions that bundle HTTP Server, Database Server, and a scripting language together. XAMPP and MAMP are these kinds of solutions for the Windows and Mac OS X platforms respectively.

For better user experience, we have created a main application that allows the desired recipe to run and show its source code. Suppose you have installed and configured a local web server like XAMPP or MAMP, and the bundle code is copied within the HTTP server root content folder in the googlemaps-cookbook folder, the user can run the main application by accessing the http://localhost/googlemaps-cookbook/index.html URL in the browser.

Who this book is for

This book is great for developers who are interested in adding a simple contact map embedded in their websites as well as for those who wish to develop real-world complex GIS applications. It is also for those who want to create map-based info graphics, such as heat maps, from their geo-related data. It's assumed that you will have some experience in HTML, CSS, and JavaScript already, and also experience in simple concepts related to GIS and prior knowledge of some GIS servers or services.

Conventions

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: "We can include other contexts through the use of the include directive."

A block of code is set as follows:

<!DOCTYPE html>
<html>
    <head>
        <!-- Include Google Maps JS API -->
        <script type="text/javascript"
        src="https://maps.googleapis.com/maps/api/js?key=INSERT_YOUR_MAP_API_KEY_HERE&sensor=false"></script

New terms and important words are shown in bold.

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

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 , 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.

Customer support

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.

Downloading the example code

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.

Errata

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/submit-errata, 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

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 with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.