Obtaining location coordinates and addresses

Many devices have the ability for us to obtain the location of the user in a very precise manner. Android provides a few means to access the location, including using the network or using Global Positioning System (GPS).

How to do it...

If we are designing an app that requires the user's location, such as finding things nearby, we can use LocationManager to get the user's current location:

  1. If we are only interested in using the network provider, we only need to ask for permission to use coarse location:
    [assembly: UsesPermission(
      Manifest.Permission.AccessCoarseLocation)]
  2. If we want to use GPS, we need to use the fine location permission instead:
    [assembly: UsesPermission( Manifest.Permission.AccessFineLocation)] ...

Get Xamarin Mobile Development for Android Cookbook 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.