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:
- N=0 - a first application - http://slodge.blogspot.co.uk/2013/04/n0-first-mvvmcross-application-n1-days.html
- N=1 - tip calc - including the Android Designer and using IoC -http://slodge.blogspot.com/2013/04/n1-tipcalc-second-example-adding-ioc.html
- N=2 - Kittens - lists and tables - N=2: Lists and Kittens (N+1 days of MvvmCross)
- N=3 - Kitten Cells on iPhone - http://slodge.blogspot.co.uk/2013/04/n3-kitten-cells-on-iphone-n1-days-of.html
- N=4 - ValueConverters - http://slodge.blogspot.co.uk/2013/04/n4-valueconverters-n1-days-of-mvvmcross.html
- N=5 - ICommand and Multiple Pages - http://slodge.blogspot.co.uk/2013/04/n5-some-first-icommands-and-multiple.html
- N=6 - Books over the Network - http://slodge.blogspot.co.uk/2013/05/n6-books-over-network-n1-days-of.html
- N=7 - Books++ - a little UI refinement - http://slodge.blogspot.co.uk/2013/05/n7-adding-some-refinements-to-books-n1.html