O'Reilly logo

Xamarin Mobile Development for Android Cookbook by Matthew Leibowitz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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)] ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required