【问题标题】:How to find a devices(Hololens) latitude and longitude如何查找设备(Hololens)经纬度
【发布时间】:2019-10-10 11:40:12
【问题描述】:

如何找到我的 Hololens 设备的纬度和经度?

  • 我已经找到了相同的解决方案。我在这里分享它,因为它可能对像我这样的其他人有所帮助;-)

0

我做了很多测试并找到了使用 "http://ip-api.com/json" 的解决方案。我希望这可以帮助你。要使用它,您需要在“Assets\Plugins”文件夹下拥有“SimpleJSON.cs.cs”,您可以从此链接获取 simpleJSON.cs http://wiki.unity3d.com/index.php/SimpleJSON#Download

要使用它,只需创建一个新的 C# 脚本 LocationFinder 并粘贴以下代码并将其附加到场景中的游戏对象。

using UnityEngine;
using System.Collections;
using SimpleJSON;

public class LocationFinder: MonoBehaviour
{
    string jsonData;

    // Use this for initialization
    IEnumerator Start()
    {
        Debug.Log("Starting");
        // implememt WWW to get json data from any url 
        //http://ip-api.com/json
        string url = "http://ip-api.com/json";
        WWW www = new WWW(url);
        yield return www;

        // store text in www to json string
        if (string.IsNullOrEmpty(www.error))
        {
            jsonData = www.text;
        }
        // use simpleJSON to get values stored in JSON data for different key value pair
        JSONNode jsonNode = SimpleJSON.JSON.Parse(jsonData);
        Debug.Log("Latitude " + jsonNode["lat"].ToString());
        Debug.Log("Longtitude " + jsonNode["lon"].ToString());
    }
}

【问题讨论】:

  • 如何找到?通过查看。在哪里可以找到?我不知道。 :D
  • 快速谷歌搜索带来了这个:docs.microsoft.com/en-us/dotnet/api/… - 你试过了吗?
  • 我希望它只适用于具有内置 GPS 的设备

标签: c# unity3d


【解决方案1】:

我做了很多测试并找到了使用 "http://ip-api.com/json" 的解决方案。我希望这可以帮助你。要使用它,您需要在“Assets\Plugins”文件夹下拥有“SimpleJSON.cs.cs”,您可以从此链接获取 simpleJSON.cs http://wiki.unity3d.com/index.php/SimpleJSON#Download

要使用它,只需创建一个新的 C# 脚本 LocationFinder 并粘贴以下代码并将其附加到场景中的游戏对象。

using UnityEngine;
using System.Collections;
using SimpleJSON;

public class LocationFinder: MonoBehaviour
{
    string jsonData;

    // Use this for initialization
    IEnumerator Start()
    {
        Debug.Log("Starting");
        // implememt WWW to get json data from any url 
        //http://ip-api.com/json
        string url = "http://ip-api.com/json";
        WWW www = new WWW(url);
        yield return www;

        // store text in www to json string
        if (string.IsNullOrEmpty(www.error))
        {
            jsonData = www.text;
        }
        // use simpleJSON to get values stored in JSON data for different key value pair
        JSONNode jsonNode = SimpleJSON.JSON.Parse(jsonData);
        Debug.Log("Latitude " + jsonNode["lat"].ToString());
        Debug.Log("Longtitude " + jsonNode["lon"].ToString());
    }
}

【讨论】:

  • 我真的是这个问题的幕后黑手,没有找到合适的解决方案,最后我发现了一些东西,所以想与其他人分享它,这样它可能会对某人有所帮助。
  • 这不会给你设备的纬度和日志,这会给你你的 ISP(互联网服务提供商)站的纬度和日志
  • 您是否只是在问题字段中发布了答案,然后用相同的答案回复了您自己的“答案”?
  • @Saif - 不,他没有 - 他首先回答了自己的问题,这似乎是他一直以来的目标,因为他很难找到答案并想分享他的结果已经发现 - 在 BugFinder 发表评论之后,他编辑了他的问题并将答案放在那里,因为 BugFinder 出于某种原因不认为这个文本是一个答案 - 这就是发生的事情
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多