12 maps, geolocation, and geofencing

Post on 24-May-2015

211 Views

Category:

Technology

4 Downloads

Preview:

Click to see full reader

DESCRIPTION

Building Apps for Windows Phone 8.1 Jump Start . Videos at: http://channel9.msdn.com/Series/Building-Apps-for-Windows-Phone-8-1

TRANSCRIPT

Matthias Shapiro @matthiasshapAndy Wigley @andy_wigley

Maps, Geolocation and Geofencing

30 April 2014

Building Apps for Windows Phone 8.1 Jump Start

WinRT Apps & Silverlight

In this module…Launching mapping apps

Programming the Map control

Location APIs

Geofencing

Launching mapping apps

Mapping URI scheme—Bing Maps:

Can be used for all Windows Store and Windows XAML Phone apps

Subset on Windows Phone appsView: cp, lvl, bb, trfc, collectionSearch: where, qRoute: rtpSee MSDN// The URI to launchstring uriToLaunch = @"bingmaps:?cp=51.501156~-0.141706&lvl=17";var uri = new Uri(uriToLaunch);

Windows.System.Launcher.LaunchUriAsync(uri);

Driving & Walking Directions - ms-drive-to:

Driving - ms-drive-to:Walking - ms-walk-to:Parameters: destination.latitude destination.longitude destination.name

If no apps available, invites search for suitable app in Store

May display disambiguation dialog on Phone// The URI to launchstring uriToLaunch = @"ms-drive-to:?destination.latitude=47.6451413797194" + "&destination.longitude=-122.141964733601&destination.name=Redmond, WA";var uri = new Uri(uriToLaunch);

Windows.System.Launcher.LaunchUriAsync(uri);

Launching mapping apps

demo

Windows Runtime Apps Map Control

Many Map controls…

Silverlight 8.0/8.1 apps:Microsoft.Phone.Maps.Controls.Map- “Here Maps Control”

Windows Runtime Phone 8.1 AppsWindows.UI.Xaml.Maps.MapControl

Silverlight 7.x apps:Microsoft.Phone.Controls.Maps.Map- “Bing Maps Control” Windows 8.x Store

AppsBing.Maps.Map

The new map control: Windows.UI.Xaml.Maps.MapControlSignificant API changeGeofencingSimpler/more consistent geometry

MapIcon

MapControl.Children -> XAML objects bindable

Geopoint Improved custom tile source support

New/different in Windows Phone 8.1 mapping

Pins• XAML panel children• MapIcons

Shapes and tiles• Polyline/Polygons• Routes• Tile source• Traffic• Extruded buildings

Ways to display your content

MapItemsControl

MapControl attached properties• MapControl.Location—geopoint• MapControl.NormalizedAnchorPosition—point (0-1 in x, y)

XAML Children

There are three types • MapIcons

• Image• Text (optional)

• MapPolygons• MapPolylines

Map elements

Tiles overlay on base map

Multiple data sources• HTTPMapTileDataSource—images from web• LocalMapTileDataSource—images from disk• CustomMapTileDataSource—bitmap deferral request

MapTileLayer

TileSources

Layer drawing order

XAML Children(icon, polyline, polygon) Map

elementsForeground overlayRoad overlayArea overlay

Background overlayBackground replacement

LabelsRoadsArea (parks, industrial, etc.)

Background (land/water)

Drawing onto a Map

demo

XAML—databound small set of interactive XAML elements which must be shown

Map icons—larger amounts of elements which can be shown with best effort

Tile source—display tiled images with finer grained layering

Displaying content—the map

Tips!

Location WinRT APIs

Location service

Location service

Core logic

CellWiFi GNSS

Geofence core

Geofencing WinRT API

GeofencesMicrosoft Positionin

g Services

Geocoordinate .NET API

Geofence

software tracking

Geolocation WinRT API

• Namespace: Windows.Devices.Geolocation

• Session types:• Single position session• Use cached positions if possible

• Tracking session• Distance based or periodic

• Use DesiredAccuracyInMeters when you need more granularity than high/default

• Use PositionSource to identify how the position was acquired

Geolocation API recapParity with Windows 8.1

Supported in: Windows Store apps

Windows Phone Store apps (Silverlight 8, Silverlight 8.1, WinRt )

How to Get the Current Location

Geolocator geolocator = new Geolocator(); geolocator.DesiredAccuracyInMeters = 50; try { Geoposition geoposition = await geolocator.GetGeopositionAsync( maximumAge: TimeSpan.FromMinutes(5), timeout: TimeSpan.FromSeconds(10) ); LatitudeTextBlock.Text = geoposition.Coordinate.Latitude.ToString("0.00"); LongitudeTextBlock.Text = geoposition.Coordinate.Longitude.ToString("0.00"); } catch (UnauthorizedAccessException) { // the app does not have the right capability or the location master switch is off StatusTextBlock.Text = "location is disabled in phone settings."; }

How to Track Location

private void TrackLocation_Click(object sender, RoutedEventArgs e) { if (!tracking) { geolocator = new Geolocator(); geolocator.DesiredAccuracy = PositionAccuracy.High; geolocator.MovementThreshold = 100; // The units are meters. geolocator.StatusChanged += geolocator_StatusChanged; geolocator.PositionChanged += geolocator_PositionChanged; tracking = true; } else { geolocator.PositionChanged -= geolocator_PositionChanged; geolocator.StatusChanged -= geolocator_StatusChanged; geolocator = null; tracking = false; } }

Mapping services WinRT APIs

• Simple DrivingMapRouteFinderResult result = await MapRouteFinder.GetDrivingRouteAsync(a, b);

• Waypoints and Traffic MapRouteFinderResult result = await MapRouteFinder.GetDrivingRouteFromWaypointsAsync(collection, MapRouteOptimization.TimeWithTraffic);

• WalkingMapRouteFinderResult result = await MapRouteFinder.GetWalkingRouteAsync(a, b);

Windows.Services.Maps.MapRouteFinder

• Lat, long (geopoint) to postal address

MapLocationFinderResult result2 = await MapLocationFinder.FindLocationsAtAsync(point);

• Postal address and hint to lat, longMapLocationFinderResult result3 = await MapLocationFinder.FindLocationsAsync("1 Microsoft way Redmond, WA", center);

• This is not a local/places search!

Windows.Services.Maps.MapLocationFinder

Geofencing WinRT APIs

Enables contextual or automatic experiences• Used to start actions based on location

based notifications• Delight the user with relevant proposals, reminders,

data…• Get things done behalf of the user automatically

Multitasking: geofence notifications can be received in the background by a background task

What is a geofence and why use it

Geofence:virtual perimeter around a place of interest to an app/user

• Namespace: Windows.Devices.Geolocation.Geofencing

• Requires location capability• Supported in Windows 8.x and

Windows Phone 8.1 devices• Support in foreground and

background mode

Geofencing API recapParity with Windows 8.1

Supported in: Windows Store apps

Windows Phone Store apps (Silverlight 8.1, Runtime)

1. App creates fences and registers for events or background task notification

2. System tracks geofences for all apps

3. App/background task is notified when fence conditions are satisfied

4. App/background task reads notification details and performs custom actions

High-level architectureLocation serviceGeofences storageAppAppAppCreate fencesTrigger task (BG)Fence notification (FG)Background coreRead notification infoHardware based trackingGeofence tracking for all appsGeofenceMonitorOptimized, adaptive software tracking

Geofences have intuitive, easy-to-use properties.

Circular geofences are supported in this release.

A geofence consists of

Property Required/optional Values Default

Id Required String N/A

Geoshape RequiredGeocircle (BasicGeoposition + Radius)

N/A

MonitoredStates Optional Entered/Exited/Removed Entered/Exited

SingleUse Optional True/False False

DwellTime Optional Timespan 10s

StartTime Optional DateTimeOffset 0/epoch

Duration Optional Timespan 0/forever

• Lock screen pinning not needed for background mode

• Background task execution throttled by 2 minutes

• Geofence background task can use limited memory, run for limited time

• Coalesce enter/exit events• Background task can do toasts, sound, etc.

Notification center available

Geofencing differences with Windows

• Recommended radius of 50 meters or more• Recommended no more than 1000 fences per app• Limited geofences per app (about 20,000)• Hysteresis logic: enter/exit detection is asymmetric• Do not use foreground mode or background mode at

same time• Limited resources for background tasks: light

operations• Always check the time at which the event occurred, in

case there were delays launching the background task

Geofencing tips and tricks

Geofencing

demo

Mapping in Universal apps

Mapping convergence

To cut a long story short: not there yet

Bing Maps vs new Windows Runtime Maps control

Location vs GeopointGeoposition (for tracking)

Events on map (phone) vs events on shapes (Win8)

Significant delta in advanced capabilities and simulation

Is there mapping conversion at all?

Geolocation 100%Geofencing 100%Geopoint

Processing geodata in shared part of PCL

©2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, Office, Azure, System Center, Dynamics 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