Reputation: 169
How i add an addListener to GOOGLE MAPS to get MapType V3
I use
google.maps.event.addListener(map, "maptypechanged", function() {
var newMapType = map.getCurrentMapType();
alert(newMapType);
});
don't alert
Upvotes: 0
Views: 5572
Reputation: 8101
I'm not a google map expert, but at a first glance, it seems you're not listening to a valid event. Since (at least it seems by reading your code) you're passing a Map object, you should stick on valid Map events. Here (see the events table) there's no 'maptypechanged' event:
http://code.google.com/intl/it-IT/apis/maps/documentation/javascript/reference.html#Map
Maybe you want the 'maptypeid_changed' event?
Anyway, the first argument of the addEventListener method is the object that fires the event. So as the second argument, you pass an event that will be fired just by THAT object. Though, always find the docs about the object you pass as first arg (in this case Map, but could be for example a Marker object and so on..) and see what are the exact events it fires.
Upvotes: 0
Reputation: 165951
Assuming I've understood correctly, I think the event you're looking for is actually called maptypeid_changed
, and the method of the Map
class you're looking for is getMapTypeId
, which returns an instance of MapTypeId
:
google.maps.event.addListener(map, "maptypeid_changed", function() {
var newMapType = map.getMapTypeId();
alert(newMapType);
});
Docs for maptypeid_changed
:
This event is fired when the mapTypeId property changes.
The maptypechanged
event, and the getCurrentMapType
method are both from the version 2 API, which has been officially deprecated.
Upvotes: 6
Reputation: 2447
Your event is wrong! It should be like this
google.maps.event.addListener(map, "maptypeid_changed", function() {
var newMapType = map.getMapTypeId();
alert(newMapType);
});
Upvotes: 0