首页
学习
活动
专区
圈层
工具
发布

for unity3d
EN

Stack Overflow用户
提问于 2014-01-02 05:51:01
回答 1查看 3.9K关注 0票数 2

祝你新年快乐!

有人为Unity3D使用过吗?我正在尝试使用Unity3D中的Places制作一个增强现实应用程序。我遵循了所有提到的这里步骤

我首先获取设备坐标,并将这些lon提供给places url以获得JSON响应(为Android创建一个api键)。以下是我的Unity3D C#代码,

代码语言:javascript
复制
#define ANDROID
using UnityEngine;
using System.Collections;
using System.Timers;
using SimpleJSON;

public class Places : MonoBehaviour
{
    static int Neversleep;
    LocationInfo currentGPSPosition;
    string gpsString;
    public GUIStyle locStyle;
    int wait;
    float radarRadius;
    string radarType, APIkey, radarSensor;
    string googleRespStr;

    void Start ()
    {
       Screen.sleepTimeout = SleepTimeout.NeverSleep;
       radarRadius = 1000f;
       radarType = "restaurant";
       APIkey = "MyAPIkey";
       radarSensor = "false";
    }

    void RetrieveGPSData()
    {
        currentGPSPosition = Input.location.lastData;
       gpsString = "Lat: " + currentGPSPosition.latitude + "  Lon: " + currentGPSPosition.longitude + "  Alt: " + currentGPSPosition.altitude + 
         "  HorAcc: " + Input.location.lastData.horizontalAccuracy + "  VerAcc: " + Input.location.lastData.verticalAccuracy + "  TS: " + Input.location.lastData.timestamp;
    }

    void OnGUI ()
    {
       GUI.Box (ScaleRect.scaledRect(25,25,700,100), "");
       GUI.Label (ScaleRect.scaledRect(35,25,700,100), gpsString, locStyle);

       GUI.Box (ScaleRect.scaledRect(25,130,700,800), "");
       GUI.Label (ScaleRect.scaledRect(35,135,700,800), "" +googleRespStr, locStyle);

#if PC
       Debug.Log("On PC / Don't have GPS");
#elif !PC
        Input.location.Start(10f,1f);
       int wait = 1000;

        if(Input.location.isEnabledByUser)
        {
            while(Input.location.status == LocationServiceStatus.Initializing && wait>0)
            {
                wait--;
            }
            if (Input.location.status == LocationServiceStatus.Failed)
         {}

            else
         {
          RetrieveGPSData();
          StartCoroutine(Radar());
            }
        }
        else
        {
            GameObject.Find("gps_debug_text").guiText.text = "GPS not available";
        }
#endif   
    }

    IEnumerator Radar ()
    {
       string radarURL = "https://maps.googleapis.com/maps/api/place/radarsearch/json?location=" + currentGPSPosition.latitude + "," + currentGPSPosition.longitude + "&radius=" + radarRadius + "&types=" + radarType + "&sensor=false" + radarSensor + "&key=" + APIkey;
        WWW googleResp = new WWW(radarURL);
        yield return googleResp;
       googleRespStr = googleResp.text;
       print (googleRespStr);       
    }
}

我得到了正确的纬度和经度坐标,但就位置而言,我得到的只有这个,

代码语言:javascript
复制
{
   "debug_info" : [],
   "html_attributions" : [],
   "results" : [],
   "status" : "REQUEST_DENIED"
}

如果有人能帮我解决这个问题就太好了.

提前感谢!

编辑:从这里下载JSON文件并解压缩并将该文件夹放在Unity3d项目的Asset文件夹中。请参考上述代码。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-01-09 04:33:17

开始起作用了。结果,如果你把SHA-1指纹字段空了,那么google也会创建API键,它可以在应用程序中使用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20877102

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档