检查 AS3 中的地理定位是否关闭

Check if Geolocation is off in AS3

我的 AIR 应用程序中有此代码:

if (Geolocation.isSupported){
var my_geo:Geolocation = new Geolocation();
my_geo.addEventListener(GeolocationEvent.UPDATE, onGeoUpdate);
}else{
    trace("Geolocation is not supported");
}

但是如何检查 GPS 是否只是关闭?

我想要这样的东西:

if (Geolocation.isSupported){
var my_geo:Geolocation = new Geolocation();
my_geo.addEventListener(GeolocationEvent.UPDATE, onGeoUpdate);
}
if Geolocation.isOff){
trace("Your GPS is off");
}

感谢您的帮助 别的{ 追踪("Geolocation is not supported"); }

您可以使用 "Geolocation.muted".

if (Geolocation.isSupported){
    var my_geo:Geolocation = new Geolocation();
    if (my_geo.muted){
        trace("Your GPS is off");
    }
    my_geo.addEventListener(GeolocationEvent.UPDATE, onGeoUpdate);
}else{
    trace("Geolocation is not supported");
}

首先检查 Geolocation muted 属性 是真还是假,以确定是否可以访问地理定位服务(可能被关闭或者用户可能拒绝访问应用程序)

即:

if (my_geo.muted) { }

如果 muted 为 false(因此它打开),则添加一个事件处理程序来跟踪它是否在您的应用程序使用地理服务期间被关闭(因此 muted 变为 true),以便您的应用程序可以通知用户,或者如果地理服务不可用,您需要做的任何事情。

if (!my_geo.muted) { 
   // start listening for geo updates
   my_geo.addEventListener(GeolocationEvent.UPDATE, onGeoUpdate); 
}
// Listen for changes in the status of the geo service
my_geo.addEventListener(StatusEvent.STATUS, yourGEOServiceUpdateHandler);

    public function yourGEOServiceUpdateHandler(event:StatusEvent):void 
    { 
        if (my_geo.muted)
            my_geo.removeEventListener(GeolocationEvent.UPDATE, onGeoUpdate);
        else
            my_geo.addEventListener(GeolocationEvent.UPDATE, onGeoUpdate);
    }