Exemplo n.º 1
0
        /// <summary>
        /// Polls current location data.
        /// </summary>
        private void GetLocation(bool fineLocation = false)
        {
            MLLocationData newData;
            MLResult       result = fineLocation ? MLLocation.GetLastFineLocation(out newData) : MLLocation.GetLastCoarseLocation(out newData);

            if (result.IsOk)
            {
                string formattedString =
                    "Latitude:\t<i>{0}</i>\n" +
                    "Longitude:\t<i>{1}</i>\n" +
                    "Postal Code:\t<i>{2}</i>\n" +
                    "Timestamp:\t<i>{3}</i>\n" +
                    (fineLocation ? "Accuracy:\t<i>{4}</i>" : "");


                Text locationText = fineLocation ? _fineLocationText : _coarseLocationText;

                locationText.text = String.Format(formattedString,
                                                  newData.Latitude,
                                                  newData.Longitude,
                                                  newData.HasPostalCode ? newData.PostalCode : "(unknown)",
                                                  newData.Timestamp,
                                                  newData.Accuracy
                                                  );

                if (!_placedGlobe && !_placedPin)
                {
                    StartCoroutine(PlaceGlobe());
                    PlacePin(GetWorldCartesianCoords(newData.Latitude, newData.Longitude));
                }
            }
            else
            {
                if (result.Code == MLResultCode.LocationNetworkConnection)
                {
                    _statusText.text = "<color=red>Received network error, please check the network connection and relaunch the application.</color>";
                }
                else
                {
                    _statusText.text = "<color=red>Failed to retrieve location with result: " + result.Code + "</color>";
                }

                enabled = false;
                return;
            }
        }
Exemplo n.º 2
0
        /**
         * Returns the GPS location from the paired CompanionApp phone/device.
         */
        public async Task <LocationReply> GetLocation()
        {
            Logger.D(TAG, "GetLocation()");

            if (!MLLocation.IsStarted)
            {
                Logger.D(TAG, "Please start MagicLeap's MLLocation object from a GameObject/MonoBehavior before using this call.");
                // Hm, Debug: return something.
                Logger.D(TAG, "FIXME: Returning a hard coded value...");
                return(new LocationReply
                {
                    longitude = -121.955238,
                    latitude = 37.354107
                });
            }

            MLLocation.Location locData = new MLLocation.Location();
            MLResult            result  = MLLocation.GetLastFineLocation(out locData);

            Logger.D(TAG, "MLLocation result: " + result); // Ensure location is allowed.
            if (!result.Equals(MLResult.Create(MLResult.Code.Ok)))
            {
                // Try coarse instead:
                result = MLLocation.GetLastCoarseLocation(out locData);
                if (!result.Equals(MLResult.Create(MLResult.Code.Ok)))
                {
                    Logger.D(TAG, "Empty location returning");
                    return(new LocationReply {
                        longitude = 0f, latitude = 0f
                    });
                }
            }

            Logger.D(TAG, "New location returning: {" + locData.Longitude + ", " + locData.Latitude + "}");
            return(new LocationReply
            {
                longitude = locData.Longitude,
                latitude = locData.Latitude
            });
        }