【发布时间】: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 的设备