The method : Get the user's location works for me (Windows 10, VS 2019)
(test in a Winforms app, without "location capability", I get GeolocationAccessStatus.Allowed and the right location
with Geoposition pos = await geolocator.GetGeopositionAsync();)
Determine User Location
Anonymous
Hi,
ia m trying to determine the user location so that. can redirect to the store page based on his location (which is the country or state)
I know it can be done with Xamarin Essentials but what if he did not grant the access?
i though of getting the location from his IP.
I tried below code:
private string GetLocalAddress()
{
var host = Dns.GetHostEntry(Dns.GetHostName());
foreach (var ip in host.AddressList)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
return ip.ToString();
}
}
throw new Exception("Local IP Address Not Found!");
}
but getting:
System.Net.Sockets.SocketException: Could not resolve host 'iPhone'
Kindly advise..
Developer technologies | .NET | Xamarin
Developer technologies | .NET | Xamarin
A Microsoft framework for building cross-platform mobile apps using .NET and C# with native performance and user interfaces.
Developer technologies | .NET | .NET Runtime
Developer technologies | .NET | .NET Runtime
.NET: Microsoft Technologies based on the .NET software framework. Runtime: An environment required to run apps that aren't compiled to machine language.
Developer technologies | .NET | Other
Developer technologies | .NET | Other
Microsoft Technologies based on the .NET software framework. Miscellaneous topics that do not fit into specific categories.
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
1 answer
Sort by: Most helpful
-
Castorix31 91,406 Reputation points2021-07-15T13:25:37.627+00:00