-1

嗨,我一直试图在我当前的位置放置一个标记,但下面的代码一直返回到 Los Atlos,如果我取出标记它将找到我的位置,我如何让标记工作?

Ext.define('FirstApp.view.Mapd',{
extend:'Ext.Panel',
    xtype:'maps',


     config : {
        fullscreen: true,
        layout: 'fit',
       title:'Map',
        iconCls:'map',

        items: [{
            xtype:  'map',

            mapOptions : {
               useCurrentLocation: true,
                zoom : 12,
                mapTypeId : google.maps.MapTypeId.ROADMAP,
                navigationControl: true,
                navigationControlOptions: {
                    style: google.maps.NavigationControlStyle.DEFAULT
                }
            },

            listeners: {


                maprender: function(comp, map) {
                   var marker = new google.maps.Marker({
                   map : map,
                   position : map.center,
                   title : "Me",
                   animation: google.maps.Animation.BOUNCE
                       });

                    setTimeout(function() {
                          map.panTo(map.center);
                    }, 1000);
                }
            }
        }]
    }
})
4

1 回答 1

0

您的指令顺序完全错误……您需要按照以下顺序进行操作::

  1. 通过调用 geo 方法找到您当前的位置并将您的 currentLocation 更新到该位置,如下所示:

    mapOptions : { . . . 
          center : center
          zoom : 15
    },
    
    geo:new Ext.util.GeoLocation({
    
            autoUpdate:true,
            maximumAge: 0,
            timeout:2000,
            listeners:{
                locationupdate: function(geo) {
                    center = new google.maps.LatLng(geo.latitude, geo.longitude);
                    if (map.rendered)
                        map.update(center)
                    else
                        map.on('activate', map.onUpdate, map, {single: true, data: center});
                },
                locationerror: function (geo,bTimeout, bPermissionDenied, bLocationUnavailable, message) {
                    if(bLocationUnavailable){
                        alert('yayyyyour Current Location is Unavailable on this device');
                    }
                    else if (bPermissionDenied){
                        alert('Location capabilities have been disabled on this device.');
                    }      
                }
            }
        });
    
  2. 将 maprender 事件添加到地图对象的侦听器中,您可以在此处添加地图标记。
    完成上述步骤后,您的地图最终将完美地以您的 currentLocation 为中心(不会出现任何错误情况),然后您创建标记对象,并将其位置设置为地图对象的中心(因为我们已经将反对我们当前的位置,这意味着标记现在在我们当前的位置)

    maprender : function(comp, map){
                var pos1;
                pos1 = new google.maps.LatLng(lats, longs);
                pos = pos1;
                var marker = new google.maps.Marker({
                     . . . .
                });
                map.setMapTypeId(google.maps.MapTypeId.HYBRID);
    
                setTimeout( function(){map.panTo (pos);} , 1000);
            }
    
于 2013-03-26T20:31:12.397 回答