Blog Pages

Friday, May 03, 2013

N=8 - Location, Location, Location (N+1 days of MvvmCross)

Today's N+1 is about how to use the MvvmCross Location plugin - https://www.nuget.org/packages/MvvmCross.HotTuna.Plugin.Location/



I go 'quite quickly' through a 4 platform demo - taking 20 minutes to build a simple app to display your current Lat and Lng on the screen.



The steps are very simple:

  • we create a 'normal' MvvmCross app with PCL core and platform specific UIs
  • we add the Location plugin to all projects
  • we start a Watcher from the Location plugin in our ViewModel
  • we use a Watcher callback to update Lat and Lng properties in our ViewModel
  • we bind to Lat and Lng within each of the UIs



While running we do hit a few (sim)emulator limitations though - not all the emulators allow you to easily get or set the current location of the device.



Here's the action:






The source code for this sample is uploaded to: https://github.com/slodge/NPlus1DaysOfMvvmCross/tree/master/N-08-Location



In a real app, I'd never really put location directly into a ViewModel like that - I'd more likely use a singleton to host the location watcher and then use Messages to distribute the location throughout the app - guess I should N+1 about that soon too...



If anyone wants to take this any of the N+1 samples further - e.g. if you'd like to produce a screencast which adds some maps too - then please do - I'll happily tweet and blog about it to promote them :)




Previously in N+1:


No comments:

Post a Comment