-1

I use XAMARIN to Android.

How can I get GPS location even GPS is turn off?

Buflow
  • 25
  • 2
  • If the radio is turned off listening to the radio is not possible ;-) – blackapps Aug 14 '21 at 17:48
  • Your question should be: How can i get location when gps is turned off? – blackapps Aug 14 '21 at 17:49
  • And the answer is: Ask google. If you ask google google sees your public ip. And google knows all so also to which provider your public ip belongs. And knowing the provider google knows approximate location. Wifi or mobile connection should be turned on to use this feature. – blackapps Aug 14 '21 at 17:51

1 Answers1

-1

You can get the approximate location by getting ip.

Here is the interface code:

public interface IDeviceOrientationService
{
    DeviceOrientation GetOrientation();
}

Here is the code implemented in Android:

[assembly: Dependency(typeof(IPAddressManager))]
namespace App9.Droid
{
    class IPAddressManager: IIPAddressManager
    {
        public string GetIPAddress()
        {
            IPAddress[] adresses = Dns.GetHostAddresses(Dns.GetHostName());
            if (adresses != null && adresses[0] != null)
            {
                return adresses[0].ToString();
            }
            else
            {
            return null;
            }
        }
    }
}

Here is the calling code:

string myAddress = DependencyService.Get<IIPAddressManager>().GetIPAddress();
Wen xu Li
  • 1,698
  • 1
  • 4
  • 7
  • This is only a partial solution, where do you look up the IP in a geolocation API? – Cheesebaron Aug 16 '21 at 06:22
  • This link explains how to query the address by IP: https://stackoverflow.com/questions/57254116/how-to-get-device-country-address-through-ip-address?noredirect=1&lq=1 – Wen xu Li Aug 16 '21 at 07:00