Skip to main content
June 13, 2011
Question

AIR geolocation API not working on my Nexus S

  • June 13, 2011
  • 1 reply
  • 595 views

Hi All,

I tried the code snippet from Tour de flex. Every time, I see the geolocation .muted returns true.

Here is my settings: within "Location and security", --> My Location,  "Use GPS satellites" , checked;  "Use wireless networks", checked. But still g.muted in the below code returns  true every time, so I can not get any update. But interesting enough that other geolocation app, latitude, map, and poynt all work perfectly and they can find my location properly.

Can anyone shed any light on this?

Thanks in advance

David

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        title="SampleGeolocation"
        creationComplete="init(event)">
   
    <fx:Script>
        <![CDATA[
            import flash.events.GeolocationEvent;
            import flash.sensors.Geolocation;
            import mx.events.FlexEvent;
            protected var g:Geolocation = new Geolocation();   
           
            protected function init(event:Event):void 
            {
                trace("init called...");
                if (Geolocation.isSupported)
                {
                   
                    if (g.muted)
                    {
                        log.text = "Access to GPS has been muted";
                        return;
                    }
                   
                    log.text = "Finding Location...";
                    g.addEventListener(GeolocationEvent.UPDATE, onUpdate);
                    addEventListener(FlexEvent.REMOVE,onRemove);
                }
                else
                {
                    currentState = "unsupported";
                    lblSupport.text = "Geolocation is not supported on this device.";
                }   
            }
           
            protected function onUpdate(event:GeolocationEvent):void
            {
                trace("Update event called");
                log.text = "latitude = " + event.latitude +
                    "\nlongitude = " + event.longitude +
                    "\naltitude = " + event.altitude +
                    "\nverticalAccuracy = " + event.verticalAccuracy +
                    "\nhorizontalAccuracy = " + event.horizontalAccuracy +
                    "\nspeed = " + event.speed +
                    "\nheading = " + event.heading +
                    "\ntimestamp = " + event.timestamp;       
            }
           
            protected function onRemove(event:FlexEvent):void
            {
                g.removeEventListener(GeolocationEvent.UPDATE, onUpdate);               
            }
        ]]>

    </fx:Script>
    <s:states>
        <s:State name="normal"/>
        <s:State name="unsupported"/>
    </s:states>
   
    <s:layout>
        <s:VerticalLayout paddingTop="20" paddingBottom="20" paddingLeft="20" paddingRight="20" gap="40"/>
    </s:layout>
   
    <s:Label id="lblSupport" includeIn="unsupported" width="95%"/>
    <s:TextArea width="98%"
                text="The Geolocation sample displays updates to the current geographical location of the device in the form of latitudinal and longitudinal coordinates." includeIn="normal"/>
    <s:VGroup includeIn="normal" width="100%" height="65%" paddingTop="10">
        <s:Label text="Event Log:"/>
        <s:TextArea id="log" width="100%" height="90%" editable="false"/>
    </s:VGroup>
</s:View>

This topic is closed to new replies. Start a new post to keep the conversation going.

1 reply

June 13, 2011

Sorry, I forgot to add permission <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>. Now it's working.