Book Image

OpenLayers 2.10 Beginner's Guide

Book Image

OpenLayers 2.10 Beginner's Guide

Overview of this book

Table of Contents (18 chapters)
OpenLayers 2.10
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for Action – creating a Google Maps layer


Let's take a look at how to create a Google Maps layer.

  1. From this point onward, I'm going to assume that when I say "create a new map" you will use the template from http://vasir.net/openlayers_book/, or create a copy of the example from Chapter 1 and remove the WMS layer calls (they both result in the same code). So, create a new map.

  2. The first thing we'll need to do is add in a script tag to the <head> section that references the Google API library. This allows us to actually use the Google Maps library:

    <script src="http://maps.google.com/maps/api/js?sensor=false"></script>
  3. Now, we'll need to create a Google Maps layer object. We won't pass in any additional settings, so the default settings will be used. By default, we'll see the Google 'Streets' Map (we could ask for the aerial imagery layer, the physical topology layer, etc—we'll cover this soon). Add the following in your init function:

    var google_map_layer = new OpenLayers...