3 Replies Latest reply on Apr 7, 2011 7:56 AM by BigZ2011

    Trouble accessing Geolocation.addEventListener

    BigZ2011

      Hello, everyone.  I'm bulding my first mobile app in Burrito and I'm having a little trouble with the .  Testing the Geolocation.isSupported property works fine but nothing happens when I try to access the Geolocation.addEventListener property. My code is below.  Any help would be greatly appreciated!

       

      AppHome.xml:

       

      <fx:Script>
        <![CDATA[
         import flash.display.Sprite;
         import flash.display.StageAlign;
         import flash.display.StageScaleMode;
         import flash.events.GeolocationEvent;
         import flash.sensors.Geolocation;
         import flash.text.TextField;
         import flash.text.TextFormat;
         import mx.events.FlexEvent;
         private var g:Geolocation;
         private var log:TextField;
        
        
         private function gpsRun():void
         {
          lblTest.text = "";
          setUpTextField();
         
          if( Geolocation.isSupported )
          {
          
           g = new Geolocation();
           g.setRequestedUpdateInterval(100);
          
           if( g.muted )
           {
            log.appendText("Geolocation is muted");
            return; // Don't do anything if device's sensor is muted.
           }
           else
           {
            log.appendText("geo active");  // This works. Android's satellite icon also turns on.
            g.addEventListener(GeolocationEvent.UPDATE,geolocationUpdateHandler,false,0,true); //  Nothing happens
            //g.addEventListener(StatusEvent.STATUS, geoStatusHandler,false,0,true);  //  Nothing happens
           }
          }
          else
          {
           log.appendText("Geolocation is not supported");
          }
          lblTest.text += log.text.toString();
         } // END gpsRun()
        
        
         protected function geoStatusHandler(event:StatusEvent):void
         {
          g.removeEventListener(GeolocationEvent.UPDATE, geolocationUpdateHandler);
          log.appendText("\ngeoStatusHandler() \n");   //  Nothing happens
         }

         private function geolocationUpdateHandler(event:GeolocationEvent):void   //  Nothing happens
         {
          lblgeolocationUpdateHandler.text = "geolocationUpdateHandler()";
          log.appendText("latitude:" + event.latitude.toString() + "°\n");
          log.appendText("longitude:" + event.longitude.toString() + "°\n");
          log.appendText("horizontal accuracy:" + event.horizontalAccuracy.toString() + " m");
          lblTest.text += log.text.toString();
         }  
        
         private function setUpTextField():void
         {
          log = new TextField();
          var format:TextFormat = new TextFormat("_sans", 24);
          log.defaultTextFormat = format;
          log.border = true;
          log.wordWrap = true;
          log.multiline = true;
          //log.x = 10;
          //log.y = 10;
          //log.height = stage.stageHeight - 20;
          //log.width = stage.stageWidth - 20;
          //addChild(log);
          lblsetUpTextField.text = "setUpTextField()";
         }
        
        ]]>
      </fx:Script>

       


      AppName-app.xml  <<---------------------<<<<<

       


      <android>
          <manifestAdditions><![CDATA[

      <manifest android:installLocation="auto">

        <!-- See the Adobe AIR documentation for more information about setting Google Android permissions -->

        <uses-permission android:name="android.permission.INTERNET"/>
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
              <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
          <uses-configuration android:reqFiveWayNav="true"/>
          <supports-screens android:normalScreens="true"/>
          <uses-feature android:required="true" android:name="android.hardware.touchscreen.multitouch"/>
          <application android:enabled="true">
           <activity android:excludeFromRecents="false">
            <intent-filter>
             <action android:name="android.intent.action.MAIN"/>
             <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
           </activity>
          </application>

      </manifest>

      ]]></manifestAdditions>
      </android>

        • 1. Re: Trouble accessing Geolocation.addEventListener
          Shongrunden Adobe Employee

          Does your phone have GPS turned on?

          • 2. Re: Trouble accessing Geolocation.addEventListener
            BigZ2011 Level 1

            Shongrunden - thank you for having a look at my code!

             

            I went to Settings > Location and Security

             

            and Use GPS Satelllites is checked.

             

            Also, when the addEventListener code is called, my Android's satellite icon turns on.  I just can't get any event info.

             

            g.addEventListener(GeolocationEvent.UPDATE,geolocationUpdateHandler,false,0,true); // Android's satellite icon turns on, that's it.


            private function geolocationUpdateHandler(event:GeolocationEvent):void

               {
                lblgeolocationUpdateHandler.text = "geolocationUpdateHandler()";  // Label is not populated

                log.appendText("latitude:" + event.latitude + "°\n");  // this doesn't happen

                log.appendText("longitude:" + event.longitude + "°\n");  // this doesn't happen

                lblTest.text += log.text.toString();   // lblTest.Text doesn't get updated, either.
               }

            • 3. Re: Trouble accessing Geolocation.addEventListener
              BigZ2011 Level 1

              I realized what the problem was - my work place is in a really rural area and I wasn't able

              to acquire a satellite until I went into town for lunch.  The code works fine.  Thanks again for your help

              , Shongrunden!