google maps implementation in sencha touch 2 (the MVC way)

旧街凉风 提交于 2019-12-04 22:25:44

first, you have to put the map panel as item of your tab container:

{
  xtype: 'map',
  useCurrentLocation: false,
  mapOptions: {
    disableDefaultUI: true,
    zoom: 11,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }
}

next, you can refer to it in the specific controller for this view in this way:

config: {
  refs: {
    ...
    mymap: '.map',
    ...
  },
  ...
}

in that way you can have a reference of your map object in the controller by typing:

this.getMymap()

and can attach an handler to the map to make some action on it when it is rendered:

this.getMymap().on('maprender', this.onMapRender, this, { single: true });

where "onMapRender" is a method of your controller. You have to do in that way if you want, for example, render a marker over the map and center it, because before the "maprender" event dispatched by the map, you can not do any action over it (the GMap object simply does not yet exists), so, for example, in your controller, the handler could be:

onMapRender: function(e) {
    var latLngCoordinates = new google.maps.LatLng(..., ...)
        marker = new google.maps.Marker({
            position: latLngCoordinates,
            animation: google.maps.Animation.DROP,
            map: this.getMymap().getMap()
        });

    this.getMymap().setMapCenter(latLngCoordinates);
}

enjoy with it ;)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!