Windows Phone 8 Maps and Location Services
Adina TrufinescuProgram Manager Windows Phone Developer Platform
Periodic and distance based trackingDesired accuracy in metersSingle location requestCaching and timeoutPosition source
Location for Windows Phone 8
.Net APIs
Windows RuntimeAPIs
Track location changesDesired accuracy Movement thresholdPositionChangedStatusChangedStart & Stop
A-GPS
Wi-fi
Cell
Location Trackingprivate Geolocator trackingGeolocator;private TypedEventHandler<Geolocator, PositionChangedEventArgs> positionChangedHandler; public void StartTracking(){ trackingGeolocator = new Geolocator(); trackingGeolocator.MovementThreshold = 100; // or trackingGeolocator.ReportInterval = (uint)TimeSpan.FromSeconds(30).TotalMilliseconds;
positionChangedHandler = (geolocator, eventArgs) => {}; trackingGeolocator.PositionChanged += positionChangedHandler;}public void StopTracking(){ trackingGeolocator.PositionChanged -= positionChangedHandler;}
Single Location Request
public async Task<Geocoordinate> GetSinglePositionAsync(){ Geolocator geolocator = new Geolocator(); geolocator.DesiredAccuracyInMeters = 10;
Geoposition geoposition = await geolocator.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
Geocoding Latitude,Longitude to Address
Reverse Geocoding Address to Latitude,Longitude
RoutingRouteQuery, Route, RouteLeg, RouteManeuver
Part of Windows Phone ToolkitMapsUserControlPushPinToGeoCoordinate
Windows Phone Map and Services APIMap Control &ServiceAPIs
Map ToolkitExtensions
ID_CAP_MAP and ID_CAP_LOCATION
Developer Token assigned through Windows Phone Developer Center
.Net
Windows Phone 7.x Maps API
Deprecated for Windows Phone 8 AppsBing Maps ControlBing 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 BackgroundApp manifest:<defaultTask Name="_default" NavigationPage="MainPage.xaml" > <BackgroundExecution> <ExecutionType Name="LocationTracking" /> </BackgroundExecution ></defaultTask>
Actively listen for location change events
16
Background Execution Constraints
XAML apps only
A single Location Tracking App runs in the background
App runs with limited access to resources
17
Resource ManagementCPU allocation is capped at 10%App has access to• Location• Audio\Speech• Network• Storage• Sensors
No access to Camera, MicrophoneShellToast and ShellTile.Update
User Awareness and ControlID_CAP_LOCATION
Users can close the running app
Users can disable background functionality per app
DeactivationApp 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 providedNotify the user!
Application Lifecycle
running
deactivated
suspended
activated
tombstoned
Activ
ated
deactivated
Deactivated
Application Lifecycle for Location Tracking
running
running in background
suspended
activated
tombstoned
Activ
ated
RunningInB
g
deactivated
Application Lifecycle – Launching&Closing
Not Running ClosingRunningLaunchin
g
Running in Background
Launching
Launching
Closing
Application Lifecycle – Launching&Closing
Not Running ClosingRunningLaunchin
g
Running in Background
Launching
Launching
Closing
RunningInBg
Closing
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 policyOpt-in to “Resume" via manifest setting
<defaultTask Name ="_default" NavigationPage="MainPage.xaml" ActivationPolicy="Resume"/>
Apps are still suspended or tombstoned
Fast Resume UXResume previous experience for Primary tilewhen previously launched via Primary tile
Start fresh for Deep Linkswhen previously launched via Primary tile or a different Deep Link
Don’t block OnBackKeyPressthis is how users close your app
30
Navigation Events
NavigationMode.Resetraised on page at the top of the backstack; indicates that the app is relaunched
NavigationMode.Newraised 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
Top Page OnNavigatedTo
Top Page OnNavigatedFrom
NavigationMode.New
NavigationMode.Reset
New Page OnNavigatingTo
NavigationMode.New
Clear Page Stack
Cancel Navigation
NavigationMode.Reset - Resume
Top Page OnNavigatedTo
Top Page OnNavigatedFrom
NavigationMode.New
NavigationMode.Reset
Cancel Navigation
Top Page
Resume!!
!
NavigationMode.Reset – Start Fresh
Top Page OnNavigatedTo
Top Page OnNavigatedFrom
NavigationMode.New
NavigationMode.Reset
New Page OnNavigatingTo
NavigationMode.New
Clear Page Stack
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!
Maps Toolkit Extension @
http://phone.codeplex.com
App to App Communication Session
Resources
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Top Related