SlideShare ist ein Scribd-Unternehmen logo
1 von 28
Downloaden Sie, um offline zu lesen
MAPS AND LOCATION
APIS FOR WINDOWS
PHONE
Jukka Silvennoinen
Chief Engineer
Nokia Developer Offering
CONTENT.
 •   Location API usages
 •   Maps API briefly
 •   Some workarounds
 •   Examples available



        © 2012 Nokia. All rights reserved.       4/18/2013
        © 2012 Microsoft. All rights reserved.
LOCATION
API
USAGES

   © 2012 Nokia. All rights reserved.       4/18/2013
   © 2012 Microsoft. All rights reserved.
LOCATION API GENERAL INFO
•   Geolocator API is new for WP8 offers following features:
    •   Accessible from managed and native code
    •   Allows application to specify the desired accuracy of the location as well as maximum time
        allowed for acquiring one shot location result
    •   Applications can request location updates after a specified time interval or a distance
        threshold is crossed
    •   Convergent with Windows 8 with only minor differences. Most code should be reusable on
        both platforms
•   GeoCoordinateWatcher API still available in Windows Phone 8.
•   Location tracking applications can be enabled to run in the
    background
•   To enable location features add the capability: ID_CAP_LOCATION to
    the manifest file (WMAppManifest.xml)
                 © 2012 Nokia. All rights reserved.                4/18/2013
                 © 2012 Microsoft. All rights reserved.
USING THE GEOCOORDINATEWATCHER API
geolocator = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
geolocator.MovementThreshold = 20; // 20 meters
geolocator.PositionChanged += geolocator_PositionChanged;
…
private void Button_Click_1(object sender, RoutedEventArgs e)
{
      if (!tracking){
            geolocator.Start();
            tracking = true;
            StarStopBut.Content = "Stop tracking";
      } else {
            geolocator.Stop();
            tracking = false;
            StarStopBut.Content = "Start tracking";
      }
}
…
void geolocator_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> args)
{
             latitudeBox.Text = args.Position.Location.Latitude.ToString("0.00");
             longitudeBox.Text = args.Position.Location.Longitude.ToString("0.00");
}


                   © 2012 Nokia. All rights reserved.                      4/18/2013
                   © 2012 Microsoft. All rights reserved.
WP8
USING THE GEOLOCATOR API
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.PositionChanged += geolocator_PositionChanged;
             tracking = true;
             TrackLocationButton.Content = "stop tracking";
      } else {
             geolocator.PositionChanged -= geolocator_PositionChanged;
             geolocator = null;
             tracking = false;
             TrackLocationButton.Content = "track location";
             StatusTextBlock.Text = "stopped";
      }
}
void geolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args){
      Dispatcher.BeginInvoke(() => {
             LatitudeTextBlock.Text = args.Position.Coordinate.Latitude.ToString("0.00");
             LongitudeTextBlock.Text = args.Position.Coordinate.Longitude.ToString("0.00");
      });
}
                     © 2012 Nokia. All rights reserved.                            4/18/2013
                     © 2012 Microsoft. All rights reserved.
NOTE THE DIFFERENCE

System.Device.Location.GeoCoordinate: http://bit.ly/Yg9rIb
• Used by GeoCoordinateWatcher

Windows.Devices.Geolocation.Geocoordinate: http://bit.ly/Yg9wvq
• used by Geolocator, as well as Maps API in general


MyCoord = new
System.Device.Location.GeoCoordinate(Position.Coordinate.Latitude,
Position.Coordinate.Longitude);


            © 2012 Nokia. All rights reserved.       4/18/2013
            © 2012 Microsoft. All rights reserved.
WP8

REGISTER FOR BACKGROUND TRACKING
 In WMAppManifest.xml
 <DefaultTask Name="_default" NavigationPage="MainPage.xaml">
     <BackgroundExecution>
         <ExecutionType Name="LocationTracking" />
     </BackgroundExecution>
 </DefaultTask>


 In App.xaml:
 <shell:PhoneApplicationService
     Launching="Application_Launching" Closing="Application_Closing"
     Activated="Application_Activated" Deactivated="Application_Deactivated"
     RunningInBackground="Application_RunningInBackground"/>

            © 2012 Nokia. All rights reserved.       4/18/2013
            © 2012 Microsoft. All rights reserved.
WP8

TRACK IF APP IS RUNNING IN BG
 In App.xaml.cs
 private void Application_Activated(object sender, ActivatedEventArgs e)
 {
     MyGlobalObject.RunningInBackground = false;
 }
 // raised when the user navigates away from your app while it is actively
 // tracking location and your app begins to run in the background
 private void Application_RunningInBackground(object sender,
                                              RunningInBackgroundEventArgs
 args)
 {
     MyGlobalObject.RunningInBackground = true;
     // Suspend all unnecessary processing such as UI updates
 }
            © 2012 Nokia. All rights reserved.       4/18/2013
            © 2012 Microsoft. All rights reserved.
WP8

DEACTIVATION OF APPS RUNNING IN THE BACKGROUND

• Event handlers for the PositionChanged and
  StatusChanged events of the Geolocator are removed.
• GeoCoordinateWatcher.Stop().
• Battery Saver is active.
• Device memory is low.
• The user disables Location Services on the phone.
• Another app begins running in the background.
• The app has run in the background for 4 hours without
  user interaction..
         © 2012 Nokia. All rights reserved.       4/18/2013
         © 2012 Microsoft. All rights reserved.
MAP
API
USAGES
   © 2012 Nokia. All rights reserved.       4/18/2013
   © 2012 Microsoft. All rights reserved.
WP8

MAP API GENERAL INFO
• New Maps API introduced with Windows Phone 8
• Bing Maps are now deprecated, but will continue to work
• Use Bing Maps only when upgrading from WP7.5
• To enable location features add the capability:
  ID_CAP_MAP (and maybe also ID_CAP_LOCATION) to the
  manifest file (WMAppManifest.xml)
• Maps data is shared, and if downloaded before (by any
  app) you can use it offline.

         © 2012 Nokia. All rights reserved.       4/18/2013
         © 2012 Microsoft. All rights reserved.
WP8

 ADDING MAP TO THE APP
xmlns:maps="clr-namespace:Microsoft.Phone.Maps.Controls;assembly=Microsoft.Phone.Maps"
...
    <maps:Map
        Name="map1"
        Center="47.6097, -122.3331"
        ZoomLevel="10"
        Heading="90"
        Pitch="45"
        CartographicMode="Hybrid"
        ColorMode="Dark"
        PedestrianFeaturesEnabled="true"
        HorizontalAlignment="Stretch“
        VerticalAlignment="Stretch">
    </maps:Map>

                 © 2012 Nokia. All rights reserved.           4/18/2013
                 © 2012 Microsoft. All rights reserved.
WP8

SUPPORTED FUNCTIONALITY
Add content                                               User services
•   Markers (MapOverlay)                                  •   Geocoding (convert address to location)
•   Polylines, polygons (MapElement)                      •   Reverse geocoding (convert location to address)
•   Route                                                 •   Routing



Change settings
•   animation modes (parabolic, linear, none)
•   heading, pitch & zoom levels
•   map color (light/dark) modes
•   map types (road, Arial, hybrid, terrain)
•   pedestrian features & landmarks on/off’
                                                                           Full list of APIs: http://bit.ly/WkUacZ
                 © 2012 Nokia. All rights reserved.                         4/18/2013
                 © 2012 Microsoft. All rights reserved.
WP8

 ADDING ‘MARKER’
Rectangle rect = new Rectangle();
rect.Fill = new SolidColorBrush(Colors.Red);
rect.Height = 15;
rect.Width = 15;


MapOverlay overlay = new MapOverlay();
overlay.Content = rect;
overlay.GeoCoordinate = new GeoCoordinate(47.6097, -122.3331);
overlay.PositionOrigin = new Point(0.5, 0.5);


MapLayer layer = new MapLayer();
layer.Add(overlay);
MyMapControl.Layers.Add(layer);


                    © 2012 Nokia. All rights reserved.           4/18/2013
                    © 2012 Microsoft. All rights reserved.
ADDING POLYGON
                                                                                                                       WP8


GeoCoordinateCollection RectLocations = CreateRectangle(new GeoCoordinate(60.35, 24.60), new GeoCoordinate(60.25, 24.80));

//Set the polygon properties
PolyRect.Path = RectLocations;
PolyRect.FillColor = Color.FromArgb(0x55, 0x00, 0x00, 0x00);
PolyRect.StrokeColor = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF);
PolyRect.StrokeThickness = 4;

map1.MapElements.Add(PolyRect);


public static GeoCoordinateCollection CreateRectangle(GeoCoordinate topLeft, GeoCoordinate bottomRight)
{
      var locations = new GeoCoordinateCollection();
      locations.Add(new GeoCoordinate(topLeft.Latitude, topLeft.Longitude));
      locations.Add(new GeoCoordinate(topLeft.Latitude, bottomRight.Longitude));
      locations.Add(new GeoCoordinate(bottomRight.Latitude, bottomRight.Longitude));
      locations.Add(new GeoCoordinate(bottomRight.Latitude, topLeft.Longitude));
      return locations;
}




                      © 2012 Nokia. All rights reserved.                       4/18/2013
                      © 2012 Microsoft. All rights reserved.
ROUTE
                                                                                           WP8

List<GeoCoordinate> points = new List<GeoCoordinate>();
points.Add(new GeoCoordinate(47.603848, -122.029953));
points.Add(new GeoCoordinate(47.669444, -122.123889));


RouteQuery query = new RouteQuery();
query.Waypoints = points;
query.QueryCompleted += MyQuery_QueryCompleted;
query.QueryAsync();


void MyQuery_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e)
{
    Route route = e.Result;
    MapRoute mapRoute = new MapRoute(route);
    MyMapControl.AddRoute(mapRoute);


    foreach (RouteLeg leg in MyRoute.Legs)
    {
             foreach (RouteManeuver maneuver in leg.Maneuvers)
                maneuver.InstructionText;
    }
                      © 2012 Nokia. All rights reserved.                       4/18/2013
}                     © 2012 Microsoft. All rights reserved.
WP8

    REVERSEGEOCODING
ReverseGeocodeQuery geoQ = new ReverseGeocodeQuery();
geoQ.QueryCompleted += geoQ_QueryCompleted;
geoQ.GeoCoordinate = map1.Center;
geoQ.QueryAsync();


void geoQ_QueryCompleted(object sender, QueryCompletedEventArgs<IList<MapLocation>> e)
{
      if (e.Result.Count() > 0)
      {
            string showString = e.Result[0].Information.Name;
            showString = showString + "nAddress: ";
            showString = showString + "n" + e.Result[0].Information.Address.HouseNumber;
            showString = showString + "n" + e.Result[0].Information.Address.Street;
            showString = showString + "n" + e.Result[0].Information.Address.PostalCode;
            showString = showString + "n" + e.Result[0].Information.Address.City;
            showString = showString + "n" + e.Result[0].Information.Address.Country;
            showString = showString + "n" + e.Result[0].Information.Address.CountryCode;
            showString = showString + "nDescription: ";
            showString = showString + "n" + e.Result[0].Information.Description.ToString();

           MessageBox.Show(showString);
     }
}
                      © 2012 Nokia. All rights reserved.                       4/18/2013
                      © 2012 Microsoft. All rights reserved.
SOME LIMITATIONS
AND
WORKAROUNDS
   © 2012 Nokia. All rights reserved.       4/18/2013
   © 2012 Microsoft. All rights reserved.
WP8
NO DIRECT WAY FOR FITTING CONTENT(1/2)

LocationRectangle setRect = null;
setRect = LocationRectangle.CreateBoundingRectangle(myPolyGon.Path);
map1.SetView(setRect);




LocationRectangle setRect = null;
GeoCoordinate[] geoArr = new GeoCoordinate[markerLayer.Count()];
for (var p = 0; p < markerLayer.Count(); p++)
{
geoArr[p] = markerLayer[p].GeoCoordinate;
}
setRect = LocationRectangle.CreateBoundingRectangle(geoArr);
map1.SetView(setRect);




                   © 2012 Nokia. All rights reserved.                  4/18/2013
                   © 2012 Microsoft. All rights reserved.
WP8

NO DIRECT WAY FOR FITTING CONTENT´(2/2)
 double north = 0;
 double west = 0;
 double south = 0;
 double east = 0;

 north = south = polyline.Path[0].Latitude;
 west = east = polyline.Path[0].Longitude;

 foreach (var p in polyline.Path.Skip(1))
 {
      if (north < p.Latitude) north = p.Latitude;
      if (west > p.Longitude) west = p.Longitude;
      if (south > p.Latitude) south = p.Latitude;
      if (east < p.Longitude) east = p.Longitude;
 }

 setRect = new LocationRectangle(north, west, south, east);
 map1.SetView(setRect);


                 © 2012 Nokia. All rights reserved.           4/18/2013
                 © 2012 Microsoft. All rights reserved.
WP8

HIDING CONTENT
if (markerLayer != null){
      for (var i = 0; i < markerLayer.Count(); i++){
            Ellipse markker = (markerLayer[i].Content as Ellipse);
            if (markker != null){
                    if (markker.Visibility == System.Windows.Visibility.Visible){
                           markker.Visibility = System.Windows.Visibility.Collapsed;
                    }else{
                           markker.Visibility = System.Windows.Visibility.Visible;
                    }
            }
      }
}

if (poly.StrokeColor == Color.FromArgb(0xFF, 0x00, 0x00, 0xFF)){
       poly.FillColor = Color.FromArgb(0x00, 0x00, 0xFF, 0x00);
       poly.StrokeColor = Color.FromArgb(0x00, 0x00, 0x00, 0xFF);
}else{
       poly.FillColor = Color.FromArgb(0x55, 0x00, 0xFF, 0x00);
       poly.StrokeColor = Color.FromArgb(0xFF, 0x00, 0x00, 0xFF);
}
                     © 2012 Nokia. All rights reserved.                            4/18/2013
                     © 2012 Microsoft. All rights reserved.
WP8

MAKING DRAGGABLE MARKERS (1/2)
Add event handled for the touch events:
System.Windows.Input.Touch.FrameReported += Touch_FrameReported;


Add internal boolean variable draggingNow to indicate
dragging status and set it to dragging inside mouse handler
set for the marker. Also disable the map while we do
dragging
void marker_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)) {
      if (oneMarker != null){
             draggingNow = true;
             map1.IsEnabled = false;
      }
}
                  © 2012 Nokia. All rights reserved.                   4/18/2013
                  © 2012 Microsoft. All rights reserved.
WP8

MAKING DRAGGABLE MARKERS (2/2)
In Touch_FrameReported move the marker with touch
events, and stop dragging with TouchAction.Up:
void Touch_FrameReported(object sender, TouchFrameEventArgs e){
      if (draggingNow == true)
      {
             TouchPoint tp = e.GetPrimaryTouchPoint(map1);
             if (tp.Action == TouchAction.Move){
                    if (oneMarker != null) {
                           oneMarker.GeoCoordinate = map1.ConvertViewportPointToGeoCoordinate(tp.Position);
                    }
             }else if (tp.Action == TouchAction.Up){
                    draggingNow = false;
                    map1.IsEnabled = true;
             }
      }
}

                   © 2012 Nokia. All rights reserved.                      4/18/2013
                   © 2012 Microsoft. All rights reserved.
SAVE/SHARE MAP IMAGE
private void SaveButton_Click(object sender, EventArgs e)
    {
      WriteableBitmap wb = new WriteableBitmap(mapControl, null);
      wb.Render(mapControl, null);
      MemoryStream memoryStream = new MemoryStream();
      wb.SaveJpeg(memoryStream, wb.PixelWidth, wb.PixelHeight, 0, 80);

       MediaLibrary library = new MediaLibrary();
       library.SavePictureToCameraRoll("SavedMap_" + DateTime.Now.ToString() + ".jpg", memoryStream.GetBuffer());
   }




                      © 2012 Nokia. All rights reserved.                        4/18/2013
                      © 2012 Microsoft. All rights reserved.
EXAMPLES
   © 2012 Nokia. All rights reserved.       4/18/2013
   © 2012 Microsoft. All rights reserved.
WP8

ALL IN ONE PLACE
Nokia project:
http://projects.developer.nokia.com/WP8MapsExamples
1.  Hello Map                                           12.   Routing
2.  Map events                                          13.   Advanced Routing
3.  Map interaction                                     14.   Location Selector
4.  Simple Map content                                  15.   Area Selector
5.  More Map content                                    16.   LaunchDirectionsTask
6.  Draggable Marker                                    17.   LaunchMapSearchTask
7.  Map markers                                         18.   LaunchMapTask
8.  Dynamic polyline                                    19.   GetMyGeoposition
9.  My Location                                         20.   TrackMyPosition And TrackMyPositionTwo
10. Geo Coding                                          21.   TrackMeInBackground
11. Reverse Geo coding
               © 2012 Nokia. All rights reserved.                        4/18/2013
               © 2012 Microsoft. All rights reserved.
Thank you!




© 2012 Nokia. All rights reserved.            4/18/2013
© 2012 Microsoft. All rights reserved.

Weitere ähnliche Inhalte

Ähnlich wie LUMIA APP LABS: HERE MAPS AND LOCATION APIS FOR WINDOWS PHONE

Windows Phone 8 - 15 Location and Maps
Windows Phone 8 - 15 Location and MapsWindows Phone 8 - 15 Location and Maps
Windows Phone 8 - 15 Location and Maps
Oliver Scheer
 
Maps API on_mobile_dev_festbangkok
Maps API on_mobile_dev_festbangkokMaps API on_mobile_dev_festbangkok
Maps API on_mobile_dev_festbangkok
ss318
 
Deep Dive into the ArcGIS Geotrigger Service - Esri DevSummit Dubai 2013
Deep Dive into the ArcGIS Geotrigger Service - Esri DevSummit Dubai 2013Deep Dive into the ArcGIS Geotrigger Service - Esri DevSummit Dubai 2013
Deep Dive into the ArcGIS Geotrigger Service - Esri DevSummit Dubai 2013
Aaron Parecki
 
GNOME GeoClue - The Geolocation Service in Gnome
GNOME GeoClue - The Geolocation Service in GnomeGNOME GeoClue - The Geolocation Service in Gnome
GNOME GeoClue - The Geolocation Service in Gnome
William Lee
 

Ähnlich wie LUMIA APP LABS: HERE MAPS AND LOCATION APIS FOR WINDOWS PHONE (20)

Location and API Maps in Windows Phone 8
Location and API Maps in Windows Phone 8Location and API Maps in Windows Phone 8
Location and API Maps in Windows Phone 8
 
How to use geolocation in react native apps
How to use geolocation in react native appsHow to use geolocation in react native apps
How to use geolocation in react native apps
 
Developing Windows Phone Apps with Maps and Location Services
Developing Windows Phone Apps with Maps and Location ServicesDeveloping Windows Phone Apps with Maps and Location Services
Developing Windows Phone Apps with Maps and Location Services
 
Windows Phone 8 - 15 Location and Maps
Windows Phone 8 - 15 Location and MapsWindows Phone 8 - 15 Location and Maps
Windows Phone 8 - 15 Location and Maps
 
12.Maps and Location
12.Maps and Location12.Maps and Location
12.Maps and Location
 
Of Nodes and Maps (Web Mapping with Drupal - Part II)
Of Nodes and Maps (Web Mapping with Drupal - Part II)Of Nodes and Maps (Web Mapping with Drupal - Part II)
Of Nodes and Maps (Web Mapping with Drupal - Part II)
 
Zenly - Reverse geocoding
Zenly - Reverse geocodingZenly - Reverse geocoding
Zenly - Reverse geocoding
 
HTML5勉強会#23_GeoHex
HTML5勉強会#23_GeoHexHTML5勉強会#23_GeoHex
HTML5勉強会#23_GeoHex
 
DIY Uber
DIY UberDIY Uber
DIY Uber
 
Open@EDINA
Open@EDINAOpen@EDINA
Open@EDINA
 
Geolocation in Drupal
Geolocation in DrupalGeolocation in Drupal
Geolocation in Drupal
 
Phone Gap
Phone GapPhone Gap
Phone Gap
 
EDINA's Open Geo-Services
EDINA's Open Geo-ServicesEDINA's Open Geo-Services
EDINA's Open Geo-Services
 
Maps API on_mobile_dev_festbangkok
Maps API on_mobile_dev_festbangkokMaps API on_mobile_dev_festbangkok
Maps API on_mobile_dev_festbangkok
 
Deep Dive into the ArcGIS Geotrigger Service - Esri DevSummit Dubai 2013
Deep Dive into the ArcGIS Geotrigger Service - Esri DevSummit Dubai 2013Deep Dive into the ArcGIS Geotrigger Service - Esri DevSummit Dubai 2013
Deep Dive into the ArcGIS Geotrigger Service - Esri DevSummit Dubai 2013
 
International Journal of Engineering Research and Development
International Journal of Engineering Research and DevelopmentInternational Journal of Engineering Research and Development
International Journal of Engineering Research and Development
 
Geolocation and Mapping
Geolocation and MappingGeolocation and Mapping
Geolocation and Mapping
 
GNOME GeoClue - The Geolocation Service in Gnome
GNOME GeoClue - The Geolocation Service in GnomeGNOME GeoClue - The Geolocation Service in Gnome
GNOME GeoClue - The Geolocation Service in Gnome
 
SmartphoneKanto#10
SmartphoneKanto#10SmartphoneKanto#10
SmartphoneKanto#10
 
Ionic2, les développeurs web à l'assaut du mobile, BDX I/O le 21/10/2016
Ionic2, les développeurs web à l'assaut du mobile, BDX I/O le 21/10/2016Ionic2, les développeurs web à l'assaut du mobile, BDX I/O le 21/10/2016
Ionic2, les développeurs web à l'assaut du mobile, BDX I/O le 21/10/2016
 

Mehr von Microsoft Mobile Developer

Mehr von Microsoft Mobile Developer (20)

Intro to Nokia X software platform 2.0 and tools
Intro to Nokia X software platform 2.0 and toolsIntro to Nokia X software platform 2.0 and tools
Intro to Nokia X software platform 2.0 and tools
 
Lumia App Labs: Lumia SensorCore SDK beta
Lumia App Labs: Lumia SensorCore SDK betaLumia App Labs: Lumia SensorCore SDK beta
Lumia App Labs: Lumia SensorCore SDK beta
 
Nokia Asha from idea to app - Imaging
Nokia Asha from idea to app - ImagingNokia Asha from idea to app - Imaging
Nokia Asha from idea to app - Imaging
 
Healthcare apps for Nokia X and Nokia Asha
Healthcare apps for Nokia X and Nokia AshaHealthcare apps for Nokia X and Nokia Asha
Healthcare apps for Nokia X and Nokia Asha
 
Push notifications on Nokia X
Push notifications on Nokia XPush notifications on Nokia X
Push notifications on Nokia X
 
DIY Nokia Asha app usability studies
DIY Nokia Asha app usability studiesDIY Nokia Asha app usability studies
DIY Nokia Asha app usability studies
 
Lessons learned from Nokia X UI reviews
Lessons learned from Nokia X UI reviewsLessons learned from Nokia X UI reviews
Lessons learned from Nokia X UI reviews
 
Location based services for Nokia X and Nokia Asha using Geo2tag
Location based services for Nokia X and Nokia Asha using Geo2tagLocation based services for Nokia X and Nokia Asha using Geo2tag
Location based services for Nokia X and Nokia Asha using Geo2tag
 
HERE Maps for the Nokia X platform
HERE Maps for the Nokia X platformHERE Maps for the Nokia X platform
HERE Maps for the Nokia X platform
 
Nokia In-App Payment - UX considerations
Nokia In-App Payment - UX considerationsNokia In-App Payment - UX considerations
Nokia In-App Payment - UX considerations
 
Introduction to Nokia Asha SDK 1.2 (beta)
Introduction to Nokia Asha SDK 1.2 (beta)Introduction to Nokia Asha SDK 1.2 (beta)
Introduction to Nokia Asha SDK 1.2 (beta)
 
UX considerations when porting to Nokia X
UX considerations when porting to Nokia XUX considerations when porting to Nokia X
UX considerations when porting to Nokia X
 
Kids' games and educational app design
Kids' games and educational app designKids' games and educational app design
Kids' games and educational app design
 
Nokia X: opportunities for developers
Nokia X: opportunities for developersNokia X: opportunities for developers
Nokia X: opportunities for developers
 
Lumia App Labs: Nokia Imaging SDK 1.1
Lumia App Labs: Nokia Imaging SDK 1.1Lumia App Labs: Nokia Imaging SDK 1.1
Lumia App Labs: Nokia Imaging SDK 1.1
 
Intro to Nokia X software platform and tools
Intro to Nokia X software platform and toolsIntro to Nokia X software platform and tools
Intro to Nokia X software platform and tools
 
Lumia App Labs: Lessons learned from 50 windows phone 8 design consultations
Lumia App Labs: Lessons learned from 50 windows phone 8 design consultationsLumia App Labs: Lessons learned from 50 windows phone 8 design consultations
Lumia App Labs: Lessons learned from 50 windows phone 8 design consultations
 
Windows Phone 8 speech: parliamo con la nostra app
Windows Phone 8 speech: parliamo con la nostra appWindows Phone 8 speech: parliamo con la nostra app
Windows Phone 8 speech: parliamo con la nostra app
 
La pubblicazione di un'applicazione sullo store
La pubblicazione di un'applicazione sullo storeLa pubblicazione di un'applicazione sullo store
La pubblicazione di un'applicazione sullo store
 
Il pattern mvvm come strutturare al meglio il vostro progetto
Il pattern mvvm come strutturare al meglio il vostro progettoIl pattern mvvm come strutturare al meglio il vostro progetto
Il pattern mvvm come strutturare al meglio il vostro progetto
 

Kürzlich hochgeladen

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Kürzlich hochgeladen (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 

LUMIA APP LABS: HERE MAPS AND LOCATION APIS FOR WINDOWS PHONE

  • 1. MAPS AND LOCATION APIS FOR WINDOWS PHONE Jukka Silvennoinen Chief Engineer Nokia Developer Offering
  • 2. CONTENT. • Location API usages • Maps API briefly • Some workarounds • Examples available © 2012 Nokia. All rights reserved. 4/18/2013 © 2012 Microsoft. All rights reserved.
  • 3. LOCATION API USAGES © 2012 Nokia. All rights reserved. 4/18/2013 © 2012 Microsoft. All rights reserved.
  • 4. LOCATION API GENERAL INFO • Geolocator API is new for WP8 offers following features: • Accessible from managed and native code • Allows application to specify the desired accuracy of the location as well as maximum time allowed for acquiring one shot location result • Applications can request location updates after a specified time interval or a distance threshold is crossed • Convergent with Windows 8 with only minor differences. Most code should be reusable on both platforms • GeoCoordinateWatcher API still available in Windows Phone 8. • Location tracking applications can be enabled to run in the background • To enable location features add the capability: ID_CAP_LOCATION to the manifest file (WMAppManifest.xml) © 2012 Nokia. All rights reserved. 4/18/2013 © 2012 Microsoft. All rights reserved.
  • 5. USING THE GEOCOORDINATEWATCHER API geolocator = new GeoCoordinateWatcher(GeoPositionAccuracy.Default); geolocator.MovementThreshold = 20; // 20 meters geolocator.PositionChanged += geolocator_PositionChanged; … private void Button_Click_1(object sender, RoutedEventArgs e) { if (!tracking){ geolocator.Start(); tracking = true; StarStopBut.Content = "Stop tracking"; } else { geolocator.Stop(); tracking = false; StarStopBut.Content = "Start tracking"; } } … void geolocator_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> args) { latitudeBox.Text = args.Position.Location.Latitude.ToString("0.00"); longitudeBox.Text = args.Position.Location.Longitude.ToString("0.00"); } © 2012 Nokia. All rights reserved. 4/18/2013 © 2012 Microsoft. All rights reserved.
  • 6. WP8 USING THE GEOLOCATOR API 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.PositionChanged += geolocator_PositionChanged; tracking = true; TrackLocationButton.Content = "stop tracking"; } else { geolocator.PositionChanged -= geolocator_PositionChanged; geolocator = null; tracking = false; TrackLocationButton.Content = "track location"; StatusTextBlock.Text = "stopped"; } } void geolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args){ Dispatcher.BeginInvoke(() => { LatitudeTextBlock.Text = args.Position.Coordinate.Latitude.ToString("0.00"); LongitudeTextBlock.Text = args.Position.Coordinate.Longitude.ToString("0.00"); }); } © 2012 Nokia. All rights reserved. 4/18/2013 © 2012 Microsoft. All rights reserved.
  • 7. NOTE THE DIFFERENCE System.Device.Location.GeoCoordinate: http://bit.ly/Yg9rIb • Used by GeoCoordinateWatcher Windows.Devices.Geolocation.Geocoordinate: http://bit.ly/Yg9wvq • used by Geolocator, as well as Maps API in general MyCoord = new System.Device.Location.GeoCoordinate(Position.Coordinate.Latitude, Position.Coordinate.Longitude); © 2012 Nokia. All rights reserved. 4/18/2013 © 2012 Microsoft. All rights reserved.
  • 8. WP8 REGISTER FOR BACKGROUND TRACKING In WMAppManifest.xml <DefaultTask Name="_default" NavigationPage="MainPage.xaml"> <BackgroundExecution> <ExecutionType Name="LocationTracking" /> </BackgroundExecution> </DefaultTask> In App.xaml: <shell:PhoneApplicationService Launching="Application_Launching" Closing="Application_Closing" Activated="Application_Activated" Deactivated="Application_Deactivated" RunningInBackground="Application_RunningInBackground"/> © 2012 Nokia. All rights reserved. 4/18/2013 © 2012 Microsoft. All rights reserved.
  • 9. WP8 TRACK IF APP IS RUNNING IN BG In App.xaml.cs private void Application_Activated(object sender, ActivatedEventArgs e) { MyGlobalObject.RunningInBackground = false; } // raised when the user navigates away from your app while it is actively // tracking location and your app begins to run in the background private void Application_RunningInBackground(object sender, RunningInBackgroundEventArgs args) { MyGlobalObject.RunningInBackground = true; // Suspend all unnecessary processing such as UI updates } © 2012 Nokia. All rights reserved. 4/18/2013 © 2012 Microsoft. All rights reserved.
  • 10. WP8 DEACTIVATION OF APPS RUNNING IN THE BACKGROUND • Event handlers for the PositionChanged and StatusChanged events of the Geolocator are removed. • GeoCoordinateWatcher.Stop(). • Battery Saver is active. • Device memory is low. • The user disables Location Services on the phone. • Another app begins running in the background. • The app has run in the background for 4 hours without user interaction.. © 2012 Nokia. All rights reserved. 4/18/2013 © 2012 Microsoft. All rights reserved.
  • 11. MAP API USAGES © 2012 Nokia. All rights reserved. 4/18/2013 © 2012 Microsoft. All rights reserved.
  • 12. WP8 MAP API GENERAL INFO • New Maps API introduced with Windows Phone 8 • Bing Maps are now deprecated, but will continue to work • Use Bing Maps only when upgrading from WP7.5 • To enable location features add the capability: ID_CAP_MAP (and maybe also ID_CAP_LOCATION) to the manifest file (WMAppManifest.xml) • Maps data is shared, and if downloaded before (by any app) you can use it offline. © 2012 Nokia. All rights reserved. 4/18/2013 © 2012 Microsoft. All rights reserved.
  • 13. WP8 ADDING MAP TO THE APP xmlns:maps="clr-namespace:Microsoft.Phone.Maps.Controls;assembly=Microsoft.Phone.Maps" ... <maps:Map Name="map1" Center="47.6097, -122.3331" ZoomLevel="10" Heading="90" Pitch="45" CartographicMode="Hybrid" ColorMode="Dark" PedestrianFeaturesEnabled="true" HorizontalAlignment="Stretch“ VerticalAlignment="Stretch"> </maps:Map> © 2012 Nokia. All rights reserved. 4/18/2013 © 2012 Microsoft. All rights reserved.
  • 14. WP8 SUPPORTED FUNCTIONALITY Add content User services • Markers (MapOverlay) • Geocoding (convert address to location) • Polylines, polygons (MapElement) • Reverse geocoding (convert location to address) • Route • Routing Change settings • animation modes (parabolic, linear, none) • heading, pitch & zoom levels • map color (light/dark) modes • map types (road, Arial, hybrid, terrain) • pedestrian features & landmarks on/off’ Full list of APIs: http://bit.ly/WkUacZ © 2012 Nokia. All rights reserved. 4/18/2013 © 2012 Microsoft. All rights reserved.
  • 15. WP8 ADDING ‘MARKER’ Rectangle rect = new Rectangle(); rect.Fill = new SolidColorBrush(Colors.Red); rect.Height = 15; rect.Width = 15; MapOverlay overlay = new MapOverlay(); overlay.Content = rect; overlay.GeoCoordinate = new GeoCoordinate(47.6097, -122.3331); overlay.PositionOrigin = new Point(0.5, 0.5); MapLayer layer = new MapLayer(); layer.Add(overlay); MyMapControl.Layers.Add(layer); © 2012 Nokia. All rights reserved. 4/18/2013 © 2012 Microsoft. All rights reserved.
  • 16. ADDING POLYGON WP8 GeoCoordinateCollection RectLocations = CreateRectangle(new GeoCoordinate(60.35, 24.60), new GeoCoordinate(60.25, 24.80)); //Set the polygon properties PolyRect.Path = RectLocations; PolyRect.FillColor = Color.FromArgb(0x55, 0x00, 0x00, 0x00); PolyRect.StrokeColor = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF); PolyRect.StrokeThickness = 4; map1.MapElements.Add(PolyRect); public static GeoCoordinateCollection CreateRectangle(GeoCoordinate topLeft, GeoCoordinate bottomRight) { var locations = new GeoCoordinateCollection(); locations.Add(new GeoCoordinate(topLeft.Latitude, topLeft.Longitude)); locations.Add(new GeoCoordinate(topLeft.Latitude, bottomRight.Longitude)); locations.Add(new GeoCoordinate(bottomRight.Latitude, bottomRight.Longitude)); locations.Add(new GeoCoordinate(bottomRight.Latitude, topLeft.Longitude)); return locations; } © 2012 Nokia. All rights reserved. 4/18/2013 © 2012 Microsoft. All rights reserved.
  • 17. ROUTE WP8 List<GeoCoordinate> points = new List<GeoCoordinate>(); points.Add(new GeoCoordinate(47.603848, -122.029953)); points.Add(new GeoCoordinate(47.669444, -122.123889)); RouteQuery query = new RouteQuery(); query.Waypoints = points; query.QueryCompleted += MyQuery_QueryCompleted; query.QueryAsync(); void MyQuery_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e) { Route route = e.Result; MapRoute mapRoute = new MapRoute(route); MyMapControl.AddRoute(mapRoute); foreach (RouteLeg leg in MyRoute.Legs) { foreach (RouteManeuver maneuver in leg.Maneuvers) maneuver.InstructionText; } © 2012 Nokia. All rights reserved. 4/18/2013 } © 2012 Microsoft. All rights reserved.
  • 18. WP8 REVERSEGEOCODING ReverseGeocodeQuery geoQ = new ReverseGeocodeQuery(); geoQ.QueryCompleted += geoQ_QueryCompleted; geoQ.GeoCoordinate = map1.Center; geoQ.QueryAsync(); void geoQ_QueryCompleted(object sender, QueryCompletedEventArgs<IList<MapLocation>> e) { if (e.Result.Count() > 0) { string showString = e.Result[0].Information.Name; showString = showString + "nAddress: "; showString = showString + "n" + e.Result[0].Information.Address.HouseNumber; showString = showString + "n" + e.Result[0].Information.Address.Street; showString = showString + "n" + e.Result[0].Information.Address.PostalCode; showString = showString + "n" + e.Result[0].Information.Address.City; showString = showString + "n" + e.Result[0].Information.Address.Country; showString = showString + "n" + e.Result[0].Information.Address.CountryCode; showString = showString + "nDescription: "; showString = showString + "n" + e.Result[0].Information.Description.ToString(); MessageBox.Show(showString); } } © 2012 Nokia. All rights reserved. 4/18/2013 © 2012 Microsoft. All rights reserved.
  • 19. SOME LIMITATIONS AND WORKAROUNDS © 2012 Nokia. All rights reserved. 4/18/2013 © 2012 Microsoft. All rights reserved.
  • 20. WP8 NO DIRECT WAY FOR FITTING CONTENT(1/2) LocationRectangle setRect = null; setRect = LocationRectangle.CreateBoundingRectangle(myPolyGon.Path); map1.SetView(setRect); LocationRectangle setRect = null; GeoCoordinate[] geoArr = new GeoCoordinate[markerLayer.Count()]; for (var p = 0; p < markerLayer.Count(); p++) { geoArr[p] = markerLayer[p].GeoCoordinate; } setRect = LocationRectangle.CreateBoundingRectangle(geoArr); map1.SetView(setRect); © 2012 Nokia. All rights reserved. 4/18/2013 © 2012 Microsoft. All rights reserved.
  • 21. WP8 NO DIRECT WAY FOR FITTING CONTENT´(2/2) double north = 0; double west = 0; double south = 0; double east = 0; north = south = polyline.Path[0].Latitude; west = east = polyline.Path[0].Longitude; foreach (var p in polyline.Path.Skip(1)) { if (north < p.Latitude) north = p.Latitude; if (west > p.Longitude) west = p.Longitude; if (south > p.Latitude) south = p.Latitude; if (east < p.Longitude) east = p.Longitude; } setRect = new LocationRectangle(north, west, south, east); map1.SetView(setRect); © 2012 Nokia. All rights reserved. 4/18/2013 © 2012 Microsoft. All rights reserved.
  • 22. WP8 HIDING CONTENT if (markerLayer != null){ for (var i = 0; i < markerLayer.Count(); i++){ Ellipse markker = (markerLayer[i].Content as Ellipse); if (markker != null){ if (markker.Visibility == System.Windows.Visibility.Visible){ markker.Visibility = System.Windows.Visibility.Collapsed; }else{ markker.Visibility = System.Windows.Visibility.Visible; } } } } if (poly.StrokeColor == Color.FromArgb(0xFF, 0x00, 0x00, 0xFF)){ poly.FillColor = Color.FromArgb(0x00, 0x00, 0xFF, 0x00); poly.StrokeColor = Color.FromArgb(0x00, 0x00, 0x00, 0xFF); }else{ poly.FillColor = Color.FromArgb(0x55, 0x00, 0xFF, 0x00); poly.StrokeColor = Color.FromArgb(0xFF, 0x00, 0x00, 0xFF); } © 2012 Nokia. All rights reserved. 4/18/2013 © 2012 Microsoft. All rights reserved.
  • 23. WP8 MAKING DRAGGABLE MARKERS (1/2) Add event handled for the touch events: System.Windows.Input.Touch.FrameReported += Touch_FrameReported; Add internal boolean variable draggingNow to indicate dragging status and set it to dragging inside mouse handler set for the marker. Also disable the map while we do dragging void marker_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)) { if (oneMarker != null){ draggingNow = true; map1.IsEnabled = false; } } © 2012 Nokia. All rights reserved. 4/18/2013 © 2012 Microsoft. All rights reserved.
  • 24. WP8 MAKING DRAGGABLE MARKERS (2/2) In Touch_FrameReported move the marker with touch events, and stop dragging with TouchAction.Up: void Touch_FrameReported(object sender, TouchFrameEventArgs e){ if (draggingNow == true) { TouchPoint tp = e.GetPrimaryTouchPoint(map1); if (tp.Action == TouchAction.Move){ if (oneMarker != null) { oneMarker.GeoCoordinate = map1.ConvertViewportPointToGeoCoordinate(tp.Position); } }else if (tp.Action == TouchAction.Up){ draggingNow = false; map1.IsEnabled = true; } } } © 2012 Nokia. All rights reserved. 4/18/2013 © 2012 Microsoft. All rights reserved.
  • 25. SAVE/SHARE MAP IMAGE private void SaveButton_Click(object sender, EventArgs e) { WriteableBitmap wb = new WriteableBitmap(mapControl, null); wb.Render(mapControl, null); MemoryStream memoryStream = new MemoryStream(); wb.SaveJpeg(memoryStream, wb.PixelWidth, wb.PixelHeight, 0, 80); MediaLibrary library = new MediaLibrary(); library.SavePictureToCameraRoll("SavedMap_" + DateTime.Now.ToString() + ".jpg", memoryStream.GetBuffer()); } © 2012 Nokia. All rights reserved. 4/18/2013 © 2012 Microsoft. All rights reserved.
  • 26. EXAMPLES © 2012 Nokia. All rights reserved. 4/18/2013 © 2012 Microsoft. All rights reserved.
  • 27. WP8 ALL IN ONE PLACE Nokia project: http://projects.developer.nokia.com/WP8MapsExamples 1. Hello Map 12. Routing 2. Map events 13. Advanced Routing 3. Map interaction 14. Location Selector 4. Simple Map content 15. Area Selector 5. More Map content 16. LaunchDirectionsTask 6. Draggable Marker 17. LaunchMapSearchTask 7. Map markers 18. LaunchMapTask 8. Dynamic polyline 19. GetMyGeoposition 9. My Location 20. TrackMyPosition And TrackMyPositionTwo 10. Geo Coding 21. TrackMeInBackground 11. Reverse Geo coding © 2012 Nokia. All rights reserved. 4/18/2013 © 2012 Microsoft. All rights reserved.
  • 28. Thank you! © 2012 Nokia. All rights reserved. 4/18/2013 © 2012 Microsoft. All rights reserved.