Is it possible to retrieve device current location (lat/lng) xamarin.android

1073
2
Jump to solution
10-11-2018 11:51 AM
rextanner
New Contributor II

Just looking for a little example code to get started. Need location services. Visual Studio 2017; Xamarin Android project with fragments.

0 Kudos
1 Solution

Accepted Solutions
rextanner
New Contributor II

Sorry, I'm just getting rolling with Visual Studio / C# / Android. I couldn't quite work out how the example you sent was getting me to the solution. I came up with this and it works (as good as big-G from my limited experiment):

private Esri.ArcGISRuntime.Location.LocationDataSource _arcDS;
private Esri.ArcGISRuntime.Location.Location _arcLoc;

// then in the hosting class ctor:

_arcDS = new Esri.ArcGISRuntime.Location.SystemLocationDataSource();

_arcDS.LocationChanged += ezriHandler;

// later in StartTheFunAsync():
Task t = _arcDS.StartAsync();
await t;

// and finally:

public void ezriHandler(object sender, Esri.ArcGISRuntime.Location.Location esriL)
{
   _arcLoc = esriL;
   Console.WriteLine("$$$$ Esri Lat:" + _arcLoc.Position.Y);
   Console.WriteLine("$$$$ Esri Lng:" + _arcLoc.Position.X);
}

"Awesome-sauce!" As far as I can tell, it doesn't use any credits. 

View solution in original post

0 Kudos
2 Replies
NagmaYasmin
Occasional Contributor III

Hello,

Take a look of the sample link below: 

Display device location—ArcGIS Runtime SDK for .NET Samples | ArcGIS for Developers 

In addition, MapView.LocationDisplay.Position() gives the MapPoint in lat/lng coordinate

MyMapView.LocationDisplay.Location
{Esri.ArcGISRuntime.Location.Location}
Course: 0
HorizontalAccuracy: 2990
IsLastKnown: false
Position: {MapPoint[X=-117.1809, Y=34.0508, Z=0, Wkid=4326]}
Timestamp: {10/11/2018 7:48:37 PM +00:00}
Velocity: 0
VerticalAccuracy: 0

Hope that helps.

0 Kudos
rextanner
New Contributor II

Sorry, I'm just getting rolling with Visual Studio / C# / Android. I couldn't quite work out how the example you sent was getting me to the solution. I came up with this and it works (as good as big-G from my limited experiment):

private Esri.ArcGISRuntime.Location.LocationDataSource _arcDS;
private Esri.ArcGISRuntime.Location.Location _arcLoc;

// then in the hosting class ctor:

_arcDS = new Esri.ArcGISRuntime.Location.SystemLocationDataSource();

_arcDS.LocationChanged += ezriHandler;

// later in StartTheFunAsync():
Task t = _arcDS.StartAsync();
await t;

// and finally:

public void ezriHandler(object sender, Esri.ArcGISRuntime.Location.Location esriL)
{
   _arcLoc = esriL;
   Console.WriteLine("$$$$ Esri Lat:" + _arcLoc.Position.Y);
   Console.WriteLine("$$$$ Esri Lng:" + _arcLoc.Position.X);
}

"Awesome-sauce!" As far as I can tell, it doesn't use any credits. 

0 Kudos