Sencha Ext.Map在被拒绝时使用currentlurrentlocation

时间:2013-03-06 22:06:02

标签: sencha-touch sencha-touch-2

我正在使用Ext.Map

{
    xtype: 'map',
    height: '100%',
    useCurrentLocation: true,
    mapOptions: {
        zoom: 18
    }
}

我如何知道用户拒绝分享他的位置,以便显示错误?

1 个答案:

答案 0 :(得分:0)

在mapOptions ::

之后将以下内容添加到mapObject
mapOptions : { . . . 
  zoom : 18
},

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('Your Current Location is Unavailable on this device');
            }
            else if (bPermissionDenied){
                alert('Location capabilities have been disabled on this device.');
            }      
        }
    }
});