firsara
firsara

Reputation: 11

Google Maps JS API v3 - Add Map Types

How can I add Hybrid, Sattelite, Terrain, and Physical View Mode to a Google Map rendered with the Gmap Javascript API v3?

my code looks like:

var myLatlng = new google.maps.LatLng(47.283902, 11.526825);
var mapOptions = {
  zoom: 14,
  center: myLatlng,
  mapTypeId: google.maps.MapTypeId.ROADMAP,
  mapTypeControlOptions: {
    mapTypes: [google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.HYBRID, google.maps.MapTypeId.SATELLITE, google.maps.MapTypeId.TERRAIN]
  }
};

directionsService = new google.maps.DirectionsService();
directionsDisplay = new google.maps.DirectionsRenderer();
map = new google.maps.Map(document.getElementById("gmap"), mapOptions);
directionsDisplay.setMap(map);

but this doesn't seem to work!

Upvotes: 1

Views: 1961

Answers (2)

Anto Jurković
Anto Jurković

Reputation: 11258

ROADMAP, TERRAIN, SATELLITE and HYBRID are basic map types and there is no need to add them. If you want to select between them you have to enable that using map option mapTypeControl (boolean: The initial enabled/disabled state of the Map type control).

For example, using:

var mapOptions = {
    zoom: 14,
    center: myLatlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    mapTypeControl: true
};

you will get map control in the right upper corner of window. And then you can select the type of map which you prefer.

Upvotes: 1

Matt
Matt

Reputation: 21

I was looking into this same issue, when converting some old V2 maps to V3, since google is killing V2 on May 19th. In V2 that was an option, so I was being asked to add that back in.

However, in V3, satellite and hybrid are the same. The labels are on for the satellite view which is really the only difference. So, functionally, having two buttons for the satellite and hybrid views is unnecessary. The satellite button has a drop menu with the labels check box option to disable those labels.

You could of course write a custom button for it, but it would be completely redundant.

Upvotes: 2

Related Questions