Event is not being triggered for Geolocation in Fl

2019-08-28 16:53发布

I created a button that looks up the coordinates of the device. There is no errors in the code but for some reason which is eluding me, the event is not being triggered.

Here is my code:

protected function lblCheckIn_clickHandler(event:MouseEvent):void
        {
            if (Geolocation.isSupported)
            {
                lblLat.text = "Finding Location...";
                geo.addEventListener(GeolocationEvent.UPDATE, onUpdate);


            }
            else
            {
                lblLat.text = "Geolocation is not supported on this device.";
            }
        }

Later on I have the event code:

            protected function onUpdate(event:GeolocationEvent):void
        {
            if (event.horizontalAccuracy <= 10)
            {
                Lat = event.latitude.toString();
                Long = event.longitude.toString();
                lblLat.text = Lat;
                lblLong.text = Long;
                geo.removeEventListener(GeolocationEvent.UPDATE, onUpdate);
                navigator.pushView(PersonSelect);
            }
            else
            {
                lblLat.text = "Updating";
            }
        }

Oh, and I also did the usual imports

                          import flash.filesystem.File;
        import flash.sensors.Geolocation;
        import flash.events.GeolocationEvent
        import spark.events.ViewNavigatorEvent
        import flash.utils.ByteArray;

Any clues as to why my event isnt calling?

2条回答
淡お忘
2楼-- · 2019-08-28 17:24

Have you instantiated an instance of geo?

 if (Geolocation.isSupported) 
 { 
      lblLat.text = "Finding Location..."; 
      geo = new Geolocation(); 
      geo.addEventListener(GeolocationEvent.UPDATE, Update); 
 }
查看更多
甜甜的少女心
3楼-- · 2019-08-28 17:39

I worked out the ultimate cause of this specific problem. It stems from Flash Builder not installing the complete Android SDK or the IOS SDK. Once I manually installed these by copying the SDK folders to their correct paths in Adobe Flash Builder, my GPS events were called successfully.

To sum up, if you get this trouble where the code and everything looks alright but it wont call up your events, then check to make sure that your latest SDKs for Flex are installed correctly for Android and or iOS

查看更多
登录 后发表回答