【问题标题】:Get GPS location even GPS turn off with XAMARIN [closed]使用 XAMARIN 获取 GPS 位置,即使 GPS 关闭 [关闭]
【发布时间】:2023-04-04 14:29:01
【问题描述】:

我在 Android 上使用 XAMARIN。

即使 GPS 已关闭,我如何获取 GPS 位置?

【问题讨论】:

  • 如果收音机关闭,收听收音机是不可能的;-)
  • 您的问题应该是:gps 关闭时如何获取位置?
  • 答案是:问谷歌。如果你问谷歌谷歌会看到你的公共 IP。谷歌也知道您的公共 IP 属于哪个提供商。并且知道提供商谷歌知道大概的位置。应打开 Wifi 或移动连接才能使用此功能。

标签: android xamarin xamarin.android android-gps


【解决方案1】:

通过获取ip可以得到大概位置。

接口代码如下:

public interface IDeviceOrientationService
{
    DeviceOrientation GetOrientation();
}

这是在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;
            }
        }
    }
}

这里是调用代码:

string myAddress = DependencyService.Get<IIPAddressManager>().GetIPAddress();

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2016-11-22
  • 1970-01-01
  • 2014-12-03
  • 1970-01-01
  • 2014-12-14
  • 2017-07-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多