Sencha touch Sencha touch 2中未加载Ext.map标记

Sencha touch Sencha touch 2中未加载Ext.map标记,sencha-touch,sencha-touch-2,Sencha Touch,Sencha Touch 2,我使用下面的代码向地图添加标记,但在Ext.map中没有显示标记 { xtype: 'map', id :'geomap', width: '70%', height: '100%', layout: 'fit', useCurrentLocation: false, flex: 3, mapOptions: { zoom: 15, mapTypeId: google.maps.Ma

我使用下面的代码向地图添加标记,但在Ext.map中没有显示标记

{
    xtype: 'map',
    id :'geomap', 
    width: '70%', 
    height: '100%', 
    layout: 'fit',
    useCurrentLocation: false, 
    flex: 3, 
    mapOptions: {
        zoom: 15,
            mapTypeId: google.maps.MapTypeId.ROADMAP,
        mapTypeControl : false,
        navigationControl : false,
        streetViewControl : false,
        backgroundColor: 'transparent',
        disableDoubleClickZoom: true,
        draggable: true,
        keyboardShortcuts: false,
        scrollwheel: true,

    },
    initialize: function() {
        var gMap = this.getMap();

        // drop map marker
        var marker = new google.maps.Marker({
            map: gMap,
            animation: google.maps.Animation.DROP,
            position: new google.maps.LatLng (12.82787,80.219722),
            title:"Hello World!"
        });
        var geo = Ext.create('Ext.util.Geolocation', {
            autoUpdate: true,
            listeners: {
                locationupdate: function (geo) {
                    var center = new google.maps.LatLng(geo.getLatitude(), geo.getLongitude());
                    Ext.getCmp('geomap').update(center);
                    //To place the marker
                    var marker = new google.maps.Marker({
                        position: center,
                        map: Ext.getCmp('geomap').map
                    });
                    Ext.msg.alert('New latitude: ' + geo.getLatitude());
                },

                locationerror: function (geo, bTimeout, bPermissionDenied, bLocationUnavailable, message) {
                    if (bTimeout) {
                        Ext.msg.alert('Timeout occurred.');
                    } else {
                        Ext.msg.alert('Error occurred.');
                    }
                }
            }
        });
        geo.updateLocation();
    }
}

没有显示标记。请提供帮助。

初始化方法不是使用地图的合适位置,因为您无法确定地图是否已在其中渲染。您需要将代码放入事件处理程序中

然后,为了方便地找到第一个标记,您应该首先将地图居中(如下图所示)

最后,在地理位置处理程序的代码中出现了一些小错误。请参阅代码中的注释

这是您的代码的固定版本。对我来说,它适用于触摸2.2.1的两个标记。不过,我还没有测试地理定位部分,因为它在我的浏览器中不可用

{
    xtype: 'map',
    id :'geomap',
    width: '70%',
    height: '100%',
    layout: 'fit',
    useCurrentLocation: false,
    flex: 3,
    mapOptions: {
        zoom: 15,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        mapTypeControl : false,
        navigationControl : false,
        streetViewControl : false,
        backgroundColor: 'transparent',
        disableDoubleClickZoom: true,
        draggable: true,
        keyboardShortcuts: false,
        scrollwheel: true

        // Center your map to see your first marker ;)
        ,center: new google.maps.LatLng (12.82787,80.219722)
    }
    ,listeners: {
        maprender: function() {
            // Get a ref to the google map object (should be provided
            // as an argument to the listener but apparently there is
            // a bug...)
            var gMap = this.getMap();

            new google.maps.Marker({
                map: gMap,
                animation: google.maps.Animation.DROP,
                position: new google.maps.LatLng (12.82787,80.219722),
                title:"Hello World!"
            });

            var geo = Ext.create('Ext.util.Geolocation', {
                autoUpdate: true,
                listeners: {
                    locationupdate: function (geo) {
                        var center = new google.maps.LatLng(geo.getLatitude(), geo.getLongitude());
                        // This is deprecated
                        // Ext.getCmp('geomap').update(center);
                        Ext.getCmp('geomap').setMapCenter(center);
                        //To place the marker
                        var marker = new google.maps.Marker({
                            position: center,
                            // This won't work
                            // map: Ext.getCmp('geomap').map
                            //
                            // Use the ref we already have:
                            map: gMap
                            //
                            // Or you could get it this way:
                            // map: Ext.getCmp('geomap').getMap()
                        });
                        Ext.msg.alert('New latitude: ' + geo.getLatitude());
                    },

                    locationerror: function (geo, bTimeout, bPermissionDenied, bLocationUnavailable, message) {
                        if (bTimeout) {
                            Ext.Msg.alert('Timeout occurred.');
                        } else {
                            Ext.Msg.alert('Error occurred.');
                        }
                    }
                }
            });
            geo.updateLocation();
        }
    }
}

您正在尝试在(12.82787,80.219722)和当前位置创建一个标记。。我说得对吗?。。我想知道你想要实现什么?但是当我使用上面的代码时,我没有得到标记,但是点击不会显示标题,任何我必须导入的内容