最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How i add an addListener to GOOGLE MAPS to get MapType V3 - Stack Overflow

programmeradmin0浏览0评论

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

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

Share Improve this question asked Jan 16, 2012 at 9:31 KwangKungKwangKung 1691 gold badge7 silver badges17 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 6

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.

Your event is wrong! It should be like this

google.maps.event.addListener(map, "maptypeid_changed", function() {
    var newMapType = map.getMapTypeId();
    alert(newMapType);
});

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./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.

发布评论

评论列表(0)

  1. 暂无评论