Flex中的Geolocation未触发事件

时间:2012-03-13 20:36:37

标签: flex flex4 flash-builder flex4.6

我创建了一个查找设备坐标的按钮。代码中没有错误,但由于某些原因而不能解决这个问题,事件没有被触发。

这是我的代码:

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.";
            }
        }

稍后我有事件代码:

            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";
            }
        }

哦,我也做了通常的进口

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

关于为什么我的活动没有打电话的任何线索?

2 个答案:

答案 0 :(得分:1)

您是否实例化了geo的实例?

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

答案 1 :(得分:1)

我找出了这个具体问题的最终原因。它源于Flash Builder没有安装完整的Android SDK或IOS SDK。通过将SDK文件夹复制到Adobe Flash Builder中的正确路径来手动安装这些文件后,我的GPS事件被成功调用。

总而言之,如果您遇到麻烦,代码和所有内容看起来都不错,但它不会调用您的活动,那么请检查以确保为Android和/或iOS正确安装了最新的Flexs SDK