460 likes | 645 Views
Windows Phone 8 Maps and Location Services. Adina Trufinescu Program Manager Windows Phone Developer Platform. Location Service APIs Map Control and Services Location Tracking in Background Fast Resume. Agenda. Location Service API. Location for Windows Phone 8.
E N D
Windows Phone 8 Maps and Location Services Adina Trufinescu Program Manager Windows Phone Developer Platform
Location Service APIs Map Control and Services Location Tracking in Background Fast Resume Agenda
Location for Windows Phone 8 Periodic and distance based tracking Desired accuracy in meters Single location request Caching and timeout Position source • Track location changes • Desired accuracy • Movement threshold • PositionChanged • StatusChanged • Start & Stop A-GPS Wi-fi Cell .Net APIs Windows Runtime APIs
Location Tracking • private GeolocatortrackingGeolocator; • private TypedEventHandler<Geolocator, PositionChangedEventArgs> positionChangedHandler; • publicvoid StartTracking() • { • trackingGeolocator= new Geolocator(); • trackingGeolocator.MovementThreshold= 100; • // or • trackingGeolocator.ReportInterval = (uint)TimeSpan.FromSeconds(30).TotalMilliseconds; • positionChangedHandler= (geolocator, eventArgs) => {}; • trackingGeolocator.PositionChanged+= positionChangedHandler; • } • publicvoid StopTracking() • { • trackingGeolocator.PositionChanged-= positionChangedHandler; • }
Single Location Request • publicasyncTask<Geocoordinate> GetSinglePositionAsync() • { • Geolocatorgeolocator = new Geolocator(); • geolocator.DesiredAccuracyInMeters = 10; • Geopositiongeoposition = awaitgeolocator.GetGeopositionAsync(TimeSpan.FromMinutes(1), • TimeSpan.FromSeconds(30)); • return geoposition.Coordinate; • }
Tips for Location Apps • Use single location request when you can • Leverage caching for faster results • Find the right tradeoff between accuracy and timeout • Is wifi on?
Windows Phone 8 Map Control • Nokia Mapping Data110+ Countries, vector maps, 3D landmarks, new map modes • Offline MapsDownloadable by users, MapsDownloader tasks expose download and update to developers • Map ControlSmooth interactions, lag-less overlays, rotation, pitch • Route DisplayEasy to display Route calculated via Maps Services
Windows Phone Maps Services • GeocodingLatitude,Longitude to Address • Reverse Geocoding Address to Latitude,Longitude • RoutingRouteQuery, Route, RouteLeg, RouteManeuver
Windows Phone Map and Services API Part of Windows Phone Toolkit MapsUserControl PushPin ToGeoCoordinate • ID_CAP_MAP and ID_CAP_LOCATION • Developer Token assigned • through Windows Phone • Developer Center Map Control & Service APIs .Net Map Toolkit Extensions
Map Control and Services Demo Mike O’Malley Program Manager
Windows Phone 7.x Maps API • Deprecated for Windows Phone 8 AppsBing Maps Control Bing Maps Task • Continue to use for 7.x apps
Map Control and Services Takeaway • Map Control and Maps Services APIs powered by Nokia • Map Extensions Toolkit • Users can manage offline maps • Bing Map control is deprecated for 8.0
Location Tracking in Background • App manifest: • <defaultTaskName="_default"NavigationPage="MainPage.xaml" > • <BackgroundExecution> • <ExecutionTypeName="LocationTracking" /> • </BackgroundExecution> • </defaultTask> • Actively listen for location change events
Background Execution Constraints • XAML apps only • A single Location Tracking App runs in the background • App runs with limited access to resources
Resource Management • CPU allocation is capped at 10% • App has access to • Location • Audio\Speech • Network • Storage • Sensors • No access to Camera, Microphone • ShellToast and ShellTile.Update
User Awareness and Control • ID_CAP_LOCATION • Users can close the running app • Users can disable background • functionality per app
Deactivation • App runs in the background until: • App stops tracking location • User disables Location Services • 4 hours without bringing the app in the foreground • Battery Saver ON • Another Location Tracking app moves to background • Low memory • DeactivationReason provided • Notify the user!
App Lifecycle Events • PhoneApplicationService Launching Deactivated RunningInBackground Activated Closed
Application Lifecycle Activated Deactivated tombstoned deactivated
Application Lifecycle for Location Tracking Activated RunningInBg tombstoned deactivated
Application Lifecycle – Launching&Closing Not Running Closing Launching Running Launching Launching Closing Running in Background
Application Lifecycle – Launching&Closing Not Running Closing Launching Running Launching Launching Closing RunningInBg Closing Running in Background
Tips for Running in Background Use sound and toasts wisely Inform the user when the app was deactivated Stop active timers and animations Stop tracking location when done Optimize for Fast Resume
Fast Resume for Windows Phone 8 Apps • “Replace” is the default activation policy • Opt-in to “Resume" via manifest setting • <defaultTaskName ="_default"NavigationPage="MainPage.xaml" • ActivationPolicy="Resume"/> • Apps are still suspended or tombstoned
Fast Resume UX • Resume previous experience for Primary tile • when previously launched via Primary tile • Start fresh for Deep Links • when previously launched via Primary tile or a different Deep Link • Don’t block OnBackKeyPress • this is how users close your app
Backstack – Clear page stack Reset: Clear the page stack
Backstack - Cancel navigation Reset: Cancel navigation
Navigation Events • NavigationMode.Reset • raised on page at the top of the backstack; indicates that the app is relaunched • NavigationMode.New • raised when a page is created for new launch Uri • NavigationMode.Refresh • raised when launch Uri is same as the page at the top of the backstack
NavigationMode.Reset Clear Page Stack Cancel Navigation NavigationMode.New Top Page OnNavigatedTo Top Page OnNavigatedFrom New Page OnNavigatingTo NavigationMode.Reset NavigationMode.New
NavigationMode.Reset - Resume Cancel Navigation NavigationMode.New Top Page OnNavigatedTo Top Page OnNavigatedFrom Top Page Resume!!! NavigationMode.Reset
NavigationMode.Reset – Start Fresh Clear Page Stack NavigationMode.New Top Page OnNavigatedTo Top Page OnNavigatedFrom New Page OnNavigatingTo NavigationMode.Reset NavigationMode.New
Fast Resume Takeaway • Main Tile: Resume! • Deep Links: Clear the back stack • OnBackKeyPress: Do not block • Test relaunch: between primary tile and deep links • Don’t forget Tombstoning!
Take Away • Map Control and Map Services powered by Nokia • Windows Runtime Location APIs • Background Execution for Location Tracking Apps • Want to resume fast? Use Fast Resume!
Resources • Maps Toolkit Extension @ • http://phone.codeplex.com • App to App Communication Session