Event is not being triggered for Geolocation in Flex

前提是你 提交于 2019-12-11 16:06:43

问题


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?


回答1:


Have you instantiated an instance of geo?

 if (Geolocation.isSupported) 
 { 
      lblLat.text = "Finding Location..."; 
      geo = new Geolocation(); 
      geo.addEventListener(GeolocationEvent.UPDATE, Update); 
 }



回答2:


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



来源:https://stackoverflow.com/questions/9691698/event-is-not-being-triggered-for-geolocation-in-flex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!