Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Issues when trying to get the latitude and longitude of a phone without internet

$
0
0

I am currently trying to have my Nexus 4 show toast notifications containing the latitude and longitude of my phone with only GPS enabled, without internet. My issue is that nothing is being displayed. I'm using the GeoLocator plugin.

Code:

using Android.App;
using Android.OS;
using Android.Widget;
using Plugin.Geolocator;

namespace Tracker {

    [Activity(Label = "Tracker", MainLauncher = true, Icon = "@mipmap/icon", Theme = "@android:style/Theme.Black.NoTitleBar")]
    public class MainActivity : Activity {

        protected override void OnCreate(Bundle savedInstanceState) {

            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.Main);

            var locator = CrossGeolocator.Current;

            locator.PositionChanged += (sender, e) => {

                var position = e.Position;
                string message = "Latitude: " + position.Latitude + " | " + "Longitude: " + position.Longitude;

                Toast.MakeText(this, message, ToastLength.Long).Show();

            };

        }

    }

}

Permissions:

  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>