Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Google Maps JavaScript API Cookbook
Google Maps JavaScript API Cookbook

Google Maps JavaScript API Cookbook: This book will help you use the amazing resource that is Google Maps to your own ends. From showing maps on mobiles to creating GIS applications, this lively, recipe-packed guide is all you need.

eBook
€20.98 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Google Maps JavaScript API Cookbook

Chapter 2. Adding Raster Layers

In this chapter, we will cover:

  • Styling of Google base maps
  • Using different tile sources as base maps
  • Adding tile overlays to maps
  • Adding image overlays to maps
  • Changing the transparency of overlays
  • Creating a heat map
  • Adding a traffic layer
  • Adding a transit layer
  • Adding a bicycling layer
  • Adding weather and cloud layers
  • Adding a Panoramio layer

Introduction

This chapter will cover everything about working with raster layers. The collection of recipes is composed of the most common use cases of handling raster layers in the Google Maps JavaScript API.

Raster is one of the prime data types in the GIS world. The Google Maps JavaScript API presents an extensive set of tools to integrate external sources of imagery. Also, the API enables application developers to change the styling of its base maps with a palette of practically unlimited array of choices.

This chapter will introduce you to changing the styling of base maps and will then continue by covering how to display raster data, focusing on external TMS (Tile Map Services), where the raster layer is composed of organized tiles in the map display (for example, OpenStreetMap). Lastly, there are a number of raster layers (traffic, transit, weather, bicycle, and Panoramio) that can be presented on the map by integrating them with the Google Maps JavaScript API.

Styling of Google base maps

Google base maps show a variety of details such as water bodies (oceans, seas, rivers, lakes, and so on), roads, parks, and built-up areas (residential, industrial, and so on). As you have observed in the first chapter, all these are shown in predefined cartographic parameters. With the styling capability of base maps, you have a virtually unlimited set of choices in terms of the cartographic representation of base maps.

In your web or mobile applications, it is very beneficial to have a diversity of representations (in all different color schemes with different emphasis) in order to keep your audience more involved; maps blend neatly into your website design.

This recipe will guide you through the process of changing the styling of base maps.

Getting ready

We can continue from the Creating a simple map in a custom DIV element recipe from Chapter 1, Google Maps JavaScript API Basics, as we do not need to recall the basics of creating the map.

How to do it…...

Using different tile sources as base maps

Google base maps display an immense amount of content (local POI information, road hierarchies, driving directions, and so on) and a large styling palette. In addition, it provides tools to change the styling of its base maps in its JavaScript API.

Moreover, you can have your other map tile sources displayed as base maps in the Google Maps interface. This feature enables you to display your tiled maps in the Google Maps interface, utilizing most of the tools of the Google Maps JavaScript API.

In this recipe, we will go through displaying OpenStreetMap tiles as base maps in the Google Maps interface, using the JavaScript API.

Getting ready

We can continue on from the Creating a simple map in a custom DIV element recipe from Chapter 1, Google Maps JavaScript API Basics, as we do not need to reiterate the basics of getting the map on screen.

How to do it…

With this recipe, you will see the OpenStreetMap tiles on top of Google Maps after completing...

Adding tile overlays to maps

Google Maps has a selection of base maps as street maps and satellite imagery, which we discussed in the previous chapter; we will now discuss how additional base maps can be introduced to the Google Maps interface.

We can also use tiled map services as overlays to the base maps. By overlay, you can think of a separate sheet of map tiles put over the base maps. You can observe the details of the overlaid layer together with the base map. Examples of overlay layers might be of the boundaries of areas of interest, special POIs that are not found in the Google Maps' base maps, statistical results to be presented with aerial or point styling, and so on.

The tile map services that are used as base maps can technically be used as overlays in the Google Maps JavaScript API. However, using these tile map services (such as OpenStreetMaps) as overlays results in blocking the original base maps of Google Maps, as there would be no blank space in the map of overlaid...

Adding image overlays to maps

Overlaying tiled map services is a big capability on hand. It enables a variety of tiled map services that come into the scene using the Google Maps API. The existing stock of tiled map services are, in general, global map services, which means that they cover the whole world or at least some continent/country.

We may be interested, for instance, to overlay a map for a university campus, having its rough plan on hand. Or, we may have found some map of a historical sheet and want to make use of it. Or, we may have an internal building plan of a particular building and we would like to see this building plan on top of Google Maps.

Is it possible to overlay these microscale images on top of Google Maps? Yes, certainly! In fact, technically, there would be no difference between using campus plans or building plans instead of tiled map services as overlays. The important thing to note is that those plan sheets should be aligned as tiles similar to the tiled map services...

Introduction


This chapter will cover everything about working with raster layers. The collection of recipes is composed of the most common use cases of handling raster layers in the Google Maps JavaScript API.

Raster is one of the prime data types in the GIS world. The Google Maps JavaScript API presents an extensive set of tools to integrate external sources of imagery. Also, the API enables application developers to change the styling of its base maps with a palette of practically unlimited array of choices.

This chapter will introduce you to changing the styling of base maps and will then continue by covering how to display raster data, focusing on external TMS (Tile Map Services), where the raster layer is composed of organized tiles in the map display (for example, OpenStreetMap). Lastly, there are a number of raster layers (traffic, transit, weather, bicycle, and Panoramio) that can be presented on the map by integrating them with the Google Maps JavaScript API.

Styling of Google base maps


Google base maps show a variety of details such as water bodies (oceans, seas, rivers, lakes, and so on), roads, parks, and built-up areas (residential, industrial, and so on). As you have observed in the first chapter, all these are shown in predefined cartographic parameters. With the styling capability of base maps, you have a virtually unlimited set of choices in terms of the cartographic representation of base maps.

In your web or mobile applications, it is very beneficial to have a diversity of representations (in all different color schemes with different emphasis) in order to keep your audience more involved; maps blend neatly into your website design.

This recipe will guide you through the process of changing the styling of base maps.

Getting ready

We can continue from the Creating a simple map in a custom DIV element recipe from Chapter 1, Google Maps JavaScript API Basics, as we do not need to recall the basics of creating the map.

How to do it…

The end...

Using different tile sources as base maps


Google base maps display an immense amount of content (local POI information, road hierarchies, driving directions, and so on) and a large styling palette. In addition, it provides tools to change the styling of its base maps in its JavaScript API.

Moreover, you can have your other map tile sources displayed as base maps in the Google Maps interface. This feature enables you to display your tiled maps in the Google Maps interface, utilizing most of the tools of the Google Maps JavaScript API.

In this recipe, we will go through displaying OpenStreetMap tiles as base maps in the Google Maps interface, using the JavaScript API.

Getting ready

We can continue on from the Creating a simple map in a custom DIV element recipe from Chapter 1, Google Maps JavaScript API Basics, as we do not need to reiterate the basics of getting the map on screen.

How to do it…

With this recipe, you will see the OpenStreetMap tiles on top of Google Maps after completing the given...

Adding tile overlays to maps


Google Maps has a selection of base maps as street maps and satellite imagery, which we discussed in the previous chapter; we will now discuss how additional base maps can be introduced to the Google Maps interface.

We can also use tiled map services as overlays to the base maps. By overlay, you can think of a separate sheet of map tiles put over the base maps. You can observe the details of the overlaid layer together with the base map. Examples of overlay layers might be of the boundaries of areas of interest, special POIs that are not found in the Google Maps' base maps, statistical results to be presented with aerial or point styling, and so on.

The tile map services that are used as base maps can technically be used as overlays in the Google Maps JavaScript API. However, using these tile map services (such as OpenStreetMaps) as overlays results in blocking the original base maps of Google Maps, as there would be no blank space in the map of overlaid tile map...

Adding image overlays to maps


Overlaying tiled map services is a big capability on hand. It enables a variety of tiled map services that come into the scene using the Google Maps API. The existing stock of tiled map services are, in general, global map services, which means that they cover the whole world or at least some continent/country.

We may be interested, for instance, to overlay a map for a university campus, having its rough plan on hand. Or, we may have found some map of a historical sheet and want to make use of it. Or, we may have an internal building plan of a particular building and we would like to see this building plan on top of Google Maps.

Is it possible to overlay these microscale images on top of Google Maps? Yes, certainly! In fact, technically, there would be no difference between using campus plans or building plans instead of tiled map services as overlays. The important thing to note is that those plan sheets should be aligned as tiles similar to the tiled map services...

Changing the transparency of overlays


The Google Maps JavaScript API supports third-party tiled map services or images to be overlaid on top of base maps. However, there is a problem with the overlay layers; they come on top of base maps and make them invisible. Of course, you can turn them on or off according to your choice; however, this is not a solution if you want to see the base maps together with the overlay layers.

In fact, you can just modify the opacity of the overlay layers to see the base maps and the overlay layers.

This recipe is focused on changing the transparency of the overlay layers introduced in the last two recipes.

Getting ready

We can use the code introduced in the Adding tile overlays to maps recipe of this chapter and modify it a little to achieve the result. Be sure to copy the code of the recipe first.

How to do it…

You will be able to make your overlay layer transparent after completing the one-step operation presented in the following code:

  1. Just change the osmMapType...

Creating a heat map


The Google Maps API lays the foundation for several map-based analysis, including heat maps. A heat map is a form of visualization that shows the concentration of points through gradient color scales.

Points, in this respect, may be the representation of any geographically represented items such as hospitals, houses, schools, measured values of sea pollution tagged with coordinates, the location of waste collection bins, and so on. The list is practically infinite.

Heat maps are very important inputs for geostatistics. In a map display, you capture the intensity in a moment compared to the sole display of the locations of points:

The preceding screenshot depicts the location of the OpenStreetMap points layer in İstanbul, Turkey, as of July. You might just get an idea of where the concentration of points is from the preceding screenshot, but the following screenshot shows it more clearly. The most intensely concentrated locations are colored in red, whereas lesser concentrated...

Left arrow icon Right arrow icon

Key benefits

  • Add to your website's functionality by utilizing Google Maps' power
  • Full of code examples and screenshots for practical and efficient learning
  • Empowers you to build your own mapping application from the ground up

Description

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.

Who is this book for?

Google Maps JavaScript API Cookbook is for developers who wish to learn how to do anything from adding a simple embedded map to a website to developing complex GIS applications with the Google Maps JavaScript API. It is targeted at JavaScript developers who know how to get by but who are also seeking the immediacy of recipe-based advice.

What you will learn

  • Create simple maps and display them on mobile devices
  • Style your own base maps
  • Add your own tile maps as base maps or overlays
  • Show vector layers on base maps in various types such as points, polylines or polygons
  • Parse various vector formats such as KML, GeoRSS, GeoJSON, WKT, and so on
  • Create a custom UI and customize your own ways to control it
  • Respond to various events including mobile gestures
  • Add additional libraries to extend the capabilities of the API
  • Work with Google Services for geocoding, directions, StreetView, and so on
  • Integrate open source or commercial GIS servers or services

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Dec 26, 2013
Length: 316 pages
Edition : 1st
Language : English
ISBN-13 : 9781849698832
Vendor :
Google
Category :
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Dec 26, 2013
Length: 316 pages
Edition : 1st
Language : English
ISBN-13 : 9781849698832
Vendor :
Google
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 120.97
PostGIS Cookbook
€41.99
Google Maps JavaScript API Cookbook
€36.99
Learning Geospatial Analysis with Python
€41.99
Total 120.97 Stars icon
Banner background image

Table of Contents

9 Chapters
1. Google Maps JavaScript API Basics Chevron down icon Chevron up icon
2. Adding Raster Layers Chevron down icon Chevron up icon
3. Adding Vector Layers Chevron down icon Chevron up icon
4. Working with Controls Chevron down icon Chevron up icon
5. Understanding Google Maps JavaScript API Events Chevron down icon Chevron up icon
6. Google Maps JavaScript Libraries Chevron down icon Chevron up icon
7. Working with Services Chevron down icon Chevron up icon
8. Mastering the Google Maps JavaScript API through Advanced Recipes Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.3
(8 Ratings)
5 star 37.5%
4 star 50%
3 star 12.5%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Tanongkiet Upanno Jun 18, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I love this kind of IT book. Since it is not only explain the application features by example but also explain each coding in the example.
Amazon Verified review Amazon
VitoshAcademy May 04, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
[Disclosure - I have a blog, reviewing books and I write reviews there - [...] I have also written three articles, concerning some of the code in the book there.I was not asked by the authors or anyone to review the book, I just needed a book, concerning Google Maps API and this one was quite a good match. At lеast prior to reading the book I had almost no experience with Java Script]What this book has to offer to a reader who has almost NO experience with Java Script (like me, for example)? Actually, pretty much EVERYTHING you need to know. It starts with the ABC of Java Script and Google API, giving you one really simple example, how to build a map. In the next examples, everything build upon this first example is explained in huge details. Sometimes, I think that the authors go to much into details, but this is probably a good thing! :)What I liked - the book is really a "CookBook" - you do not need to read it page by page, chapter by chapter, but you can simply read the first chapter and the introduction and then you may go to any page, to any recipe and use it as a pro :) This is really a big plus for beginners, who do not have full 3 days to read it properly and test the code in it.What you should do after buying the book - the examples are quite well built, but they will not function on your pc immediately - that is because the google api code, which has some limitations. Thus you should go and make your own account at code.google.com and change the code from the book at that place. Fortunately, the procedure is well described.What is inside? Pretty much anything a beginner in Google API & Java Script would dream about. The table of contents is really well composed for beginners.So, my last word is the following - if you are a beginner in either Java Script or Google API - go for the book, it is suited for you! No specific pre-knowledge is required, indeed (probably, just some really basic knowledge in programming)! If you are wondering whether this book is for you, you may go to the book's website and browse the examples, which are generously provided there - at the site of the book, go to the support tab and click "Download Now". Then the code is fully at your disposal!Thank you for reading the review! I hope you have enjoyed it!Regards,vitoshacademy.com
Amazon Verified review Amazon
ervin kenan aydin Jan 31, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I have the Kindle Version of this book. It has easy to understand examples and clear explanations. I loved it!
Amazon Verified review Amazon
Cristian Scutaru Sep 16, 2014
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
In the true spirit of a "cookbook" publication, many many samples for the most recent Google Maps API.
Amazon Verified review Amazon
Fernando Doglio Mar 12, 2014
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Disclosure: I was asked by the publisher to review this book.The book“Google Maps JavaScript API Cookbook” is relatively a short book, it’s full of, like the name of the book suggests, recipes to work with the Google Maps API.Both authors, Alper Dincer and Balkan Uraz share a MS degree in Geographical Sciences and have over 10 years of experience working on Geographic Information Systems. So it’s safe to say they know their GIS. That being said, this is a programming cookbook, so the quality of the recipes is not assured.The badLet’s first start with the bad, or the not-so-good to be honest.Like I said before, the book’s authors are experts when it comes to Geographical Systems, and have worked in several Geo related projects over the last 10 years, but it shows that they are not experienced programmers.The recipes do their work, don’t get me wrong, but their code is not the best, they just don’t follow regular best practices.The entire book could’ve been thought out to end up developing a small framework to work with Google Maps API. Instead, the recepies’ code are only related to that recepie’s task instead. Leaving the reader with a bunch of individual examples and a lot of repeated code.The other programming related issue I had with this book, was that the authors kept talking about creating classes. If you’ve used JavaScript for a while, you’d know that that’s not entirely right, actually, it’s pretty misleading to the less versed developer. I know this isn’t a JavaScript-heavy book or anything like that, but they could’ve at least bothered to get the names right.The goodYeap, that’s right, that’s about all that really “bothered” me from the book. To be honest, this book is a really useful reference manual.It’s quite easy to read, each example is easily understood and very well explained. You’ll probably find yourself coming back to it, just to quickly check how something was done.Call me skeptic, but I had my doubts about the cookbook format of it. I was afraid that the lack of technical depth about the Google Maps API would hurt and hinder my learning. On the contrary, this gave me a super quick, yet complete, overview of what I could possibly accomplish with this powerful API.I had already done some easy and mid-level stuff with the API but by the end of the book, I had learned how to fully customize the map, load external data and use the services provided by the API.Would I recommend it?Yes I would, if you’re just starting, get the book and learn all you can eventually accomplish with it. If you’ve already worked with the API, get it anyways, you’ll end up learning a few tricks on the way.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.