示例#1
0
    IEnumerator GetReverseCleanPOI(BTCleanPOI poi, OnSuccessAddressCleanPOI callback)
    {
        if (poi == null)
        {
            ready = false;
            yield return(null);
        }
        Succes = false;
        string surl = string.Format("{0}?format=jsonv2&lat={1}&lon={2}&zoom={3}&addressdetails=1", url, GPSPoint.GetDoubleValue(poi.Latitude), GPSPoint.GetDoubleValue(poi.Longitude), zoomlevel);

        // email is necessary, for this service to work as stated in it's web site
        if (string.IsNullOrEmpty(email) == false)
        {
            surl = string.Format("{0}&email={1}", surl, email);
        }

        UnityWebRequest www = UnityWebRequest.Get(surl);

        yield return(www.SendWebRequest());

        while (!www.isDone)
        {
            yield return(null);
        }
        if (www.isNetworkError || www.isHttpError)
        {
            Succes = false;
            Debug.Log(www.error);
            LogManager.Instance.AddLog(string.Format("Error: Calling Reverse GPS Service: {0}", www.error));
            ready = false;
            yield return(null);
        }
        byte[]     resultdata = www.downloadHandler.data;
        string     POIJSON    = System.Text.Encoding.Default.GetString(resultdata);
        ReverseGPS revgps     = JsonUtility.FromJson <ReverseGPS>(POIJSON);

        Succes = true;

        ready = true;
        // update flag from global setting
        if (SaveReveseAddressToDatabase != GameManager.Instance.Setting.SaveReversePOIToSQLite)
        {
            SaveReveseAddressToDatabase = GameManager.Instance.Setting.SaveReversePOIToSQLite;
        }
        // now save this to database
        if (SaveReveseAddressToDatabase)
        {
            POIAddress poiad = POIAddress.GetPOIFromAddress(revgps.address, poi);
            try
            {
                if (db != null)
                {
                    // check if POI already exists in SQLite DB
                    POIAddress ad = db.GetPoiAddressByID(poi.ID);
                    if (ad == null)
                    {
                        db.InsertPoiAddress(poiad);
                        LogManager.Instance.AddLog(string.Format("Success insert to SQLite Poi: {0}", poi.ID));
                    }
                }
            }
            catch (Exception ex)
            {
                LogManager.Instance.AddLog(string.Format("Failed insert to SQLite Poi: {0} - {1}", poi.ID, ex.Message));
            }
        }
        // update the caller thru callback
        if (callback != null)
        {
            callback(poi, revgps.address);
        }
    }
示例#2
0
    IEnumerator GetPOI()
    {
        // Read GPS Position from singleton, using gps sensor of the device
        if (GPSData.Instance.Ready)
        {
            float lat   = GPSData.Instance.Latitude;
            float longt = GPSData.Instance.Longitude;
            if (lat != 0 || longt != 0) // if pc with no gps avoid it
            {
                latitude  = lat;
                longitude = longt;
            }
        }
        // now apply radius from global settings
        if (GameManager.Instance.Setting.GPSRadius > 0 && radius != GameManager.Instance.Setting.GPSRadius)
        {
            radius = GameManager.Instance.Setting.GPSRadius;
        }

        string          surl          = string.Format("{0}query?radius={1}&latitude={2}&longitude={3}", url, radius, GPSPoint.GetDoubleValue(latitude), GPSPoint.GetDoubleValue(longitude));
        string          authorization = authenticate(user, password);
        UnityWebRequest www           = UnityWebRequest.Get(surl);

        www.SetRequestHeader("AUTHORIZATION", authorization);
        www.SetRequestHeader("Content-Type", "application/json");

        // pass control until request is completed
        yield return(www.SendWebRequest());

        if (www.isNetworkError || www.isHttpError)
        {
            Debug.Log(www.error);
            LogManager.Instance.AddLog(string.Format("Error calling BT: {0}", www.error));
        }
        else
        {
            Debug.Log("Form upload complete! Status Code: " + www.responseCode);
            byte[] result  = www.downloadHandler.data;
            string POIJSON = System.Text.Encoding.Default.GetString(result);
            // prepare JSON to comply with Unity JsonUtility
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append("{ \"POI\" : ");
            sb.Append(POIJSON);
            sb.Append("}");


            BTPOIInfo info = JsonUtility.FromJson <BTPOIInfo>(sb.ToString());
            ListPoints.Clear();
            foreach (BTPOI p in info.POI)
            {
                BTCleanPOI cl = new BTCleanPOI(p);
                ListPoints.Add(cl);
//                    LogManager.Instance.AddLog(string.Format("Added POI: {0}", cl.ID));
            }

            // Debug.LogFormat("Uploaded total {0} POI from BT!", ListPoints.Count);
            LogManager.Instance.AddLog(string.Format("POI from BT - Total: {0}", ListPoints.Count));
            // now update BTManager
            BTPOIManager.Instance.ApendListData(ListPoints);
            PrevPoint = new GPSPoint()
            {
                latitude = latitude, longitude = longitude
            };
        }
    }