Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to add Google map as a layer (something like "var gmap = new OpenLayers.Layer.Google("Google Streets", {visibility: false})"?) to this mymap.js function i already have:

var map = new OpenLayers.Map({
    div: 'map',
//  allOverlays: true,
    theme: null,
    projection: sphericalMercatorProj,
    displayProjection: geographicProj,
    units: 'm',
    numZoomLevels: 18,
    maxResolution: 156543.0339,
    maxExtent: new OpenLayers.Bounds(
        -20037508.34, -20037508.34, 20037508.34, 20037508.34
    controls: [
        new OpenLayers.Control.Attribution(),
        new OpenLayers.Control.Navigation(),
        new OpenLayers.Control.PanZoom(),
        new OpenLayers.Control.LayerSwitcher()

    layers: [
        new OpenLayers.Layer.OSM('OpenStreetMap', null),
    center: new OpenLayers.LonLat(0, 0),
    zoom: 2


Note: suggested answer is fine -

    layers: [
        new OpenLayers.Layer.OSM('OpenStreetMap', null),
        new OpenLayers.Layer.Google(
        "Google Streets", // the default
        {numZoomLevels: 20},

share|improve this question
up vote 4 down vote accepted

In the layers array, just add the following:

new OpenLayers.Layer.Google(
                "Google Streets", // the default
                {numZoomLevels: 20}

In addition, you need to make sure that you refer to the Google Maps Library, by using the following tag:

  <script src=";sensor=false"></script>

For a complete sample, have a look at: Google (v3) Layer Example

share|improve this answer
Adding "new " to the layer array do not work. -> get empty screen. – volvox Apr 26 '13 at 16:51
OK i got it work with your suggestion... thanks. – volvox Apr 26 '13 at 17:12
By the way the link is broken – Menelaos Kotsollaris Sep 21 '15 at 22:27
@MenelaosKotsollaris Link has been updated; – Devdatta Tengshe Sep 22 '15 at 4:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.