GeoLocationViewModel Class

The GeoLocationViewModel.Start method instantiates either the GeolocatorProxy or a MockGeoLocator depending on the value of the viewmodel’s Boolean useMockLocator field (see Listing 17.6).

Tip

Rather than requiring the viewmodel to determine which IGeoLocator implementation it should use, Inversion of Control (IoC) could be employed to resolve the object. IoC is discussed in Chapter 24, “Unit Testing Apps.”

The Start method subscribes to the PositionChanged and StatusChanged events of the IGeoLocator, and then calls the IGeoLocator object’s Start method to begin receiving location notifications.

When the PositionChanged event is raised, the viewmodel’s GeoCoordinate property is set to the current location.

LISTING ...

Get Windows® Phone 8 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.