0

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),
        sundialsLayer,
        sprintersLayer,
        poisLayer
    ],
    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},
        )
        
        sundialsLayer,
        sprintersLayer,
        poisLayer
    ],

1 Answer 1

4

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="http://maps.google.com/maps/api/js?v=3&amp;sensor=false"></script>
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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