<?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" viewDeactivate="view1_viewDeactivateHandler(event)" title="{data.title}" xmlns:components="components.*">

<fx:Script>

<![CDATA[

import flash.sensors.Geolocation;

import spark.events.ViewNavigatorEvent;

import views.SnippetView;

private var geoLocation:Geolocation;

protected function button1_clickHandler(event:MouseEvent):void

{

// TODO Auto-generated method stub

if(Geolocation.isSupported==true){

geoLocation = new Geolocation();

geoLocation.setRequestedUpdateInterval(1000);

geoLocation.addEventListener(GeolocationEvent.UPDATE, handleLocationRequest);

} else {

geoStatus.text = "Geolocation feature not supported"; 

}

}

private function handleLocationRequest(event:GeolocationEvent):void { 

var mph:Number = event.speed*2.23693629;

var kph:Number = event.speed*3.6;

geoStatus.text = "Updated: " + new Date().toString();

geoResponse.text = "latitude: " + event.latitude.toString() + "\n" 

+ "longitude: " + event.longitude.toString() + "\n" 

+ "altitude: " + event.altitude.toString()  + "\n"

+ "speed: " + event.speed.toString()  + "\n"

+ "speed: " + mph.toString()  + " MPH \n"

+ "speed: " + kph.toString()  + " KPH \n"

+ "heading: " + event.heading.toString()  + "\n"

+ "horizontal accuracy: " + event.horizontalAccuracy.toString()  + "\n"

+ "vertical accuracy: " + event.verticalAccuracy.toString() 

}

protected function view1_viewDeactivateHandler(event:ViewNavigatorEvent):void

{

// TODO Auto-generated method stub

geoLocation.removeEventListener(GeolocationEvent.UPDATE, handleLocationRequest);

}

]]>

</fx:Script>

<s:navigationContent>

<s:Button label="Snippet" click="navigator.pushView(views.SnippetView,data)"/>

<s:Button label="Tutorial" click="navigateToURL(new URLRequest(data.tutorial))"/>

</s:navigationContent>

<s:VGroup gap="10" paddingLeft="5" paddingTop="5">

<s:Button label="Locate me" click="button1_clickHandler(event)"/>

<s:Label id="geoStatus" width="600"/>

<s:Label id="geoResponse" width="600" height="400" maxDisplayedLines="12"/>

</s:VGroup>

<components:QuestionBlock bottom="40" horizontalCenter="0" questionData="{data}"/>

</s:View>