1

Im experimenting with flashbuilder 4.6 and am using this simple / bare-bones geolocation code I found online to do some testing as I try to learn more about it and how it might be used...

one thing I am curious to know is how to stop / interrupt the geolocation routine so that it STOPS polling for the location and waits for the user to 'start' the geolocation.

if I use clearInterval(interval); that can stop the loop I guess -- but geo2 continues to exist and use device resources, correct? what would the code look like to use a slideToggle to control it for example?

The geolocation code snippet Im experimenting with...

private function onMapReady(e:Event):void
        {
            if (Geolocation.isSupported)
            {
                var geo = new Geolocation();
                geo.setRequestedUpdateInterval(100);
                geo.addEventListener(GeolocationEvent.UPDATE, geolocationUpdateHandler);
            }
                else
                {
                    trace("No geolocation support.");
                }   
        }



        private function geolocationUpdateHandler(event:GeolocationEvent):void
        {
            trace("lat:" + event.latitude.toString() + " - ");
            trace("long:" + event.longitude.toString() + "° - ");
            trace("Accuracy:" + event.horizontalAccuracy.toString() + " m");

        }
tamak
  • 1,541
  • 2
  • 19
  • 39

1 Answers1

4

If you want to stop reacting to polling updates, just remove the listener:

geo.removeEventListener(GeolocationEvent.UPDATE, geolocationUpdateHandler);

If you want to switch off polling completely, just nullify it:

geo = null;

(and make sure you also remove any listeners first)