Exemple #1
0
        /// <summary>
        /// Polls current location data.
        /// </summary>
        private void GetLocation()
        {
            MLLocationData newData = new MLLocationData();
            MLResult       result  = MLLocation.GetLastCoarseLocation(out newData);

            if (result.IsOk)
            {
                _locationText.text = String.Format(
                    "Latitude:\t<i>{0}</i>\n" +
                    "Longitude:\t<i>{1}</i>\n" +
                    "Postal Code:\t<i>{2}</i>",
                    newData.Latitude,
                    newData.Longitude,
                    newData.HasPostalCode ? newData.PostalCode : "(unknown)"
                    );

                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>";
                    enabled          = false;
                    return;
                }
            }
        }
        /// <summary>
        /// Start the MLLocation API.
        /// </summary>
        public static MLResult Start()
        {
            MLResult result = MLPrivilegesStarterKit.Start();

            #if PLATFORM_LUMIN
            if (!result.IsOk)
            {
                Debug.LogErrorFormat("Error: MLLocationStarterKit failed starting MLPrivilegesStarterKit, Reason {0} ", result);
                return(result);
            }
            result = MLPrivilegesStarterKit.RequestPrivileges(MLPrivileges.Id.FineLocation, MLPrivileges.Id.CoarseLocation);

            if (result.Result != MLResult.Code.PrivilegeGranted)
            {
                Debug.LogErrorFormat("Error: MLLocationStarterKit failed requesting privileges, reason {0} ", result);
                return(result);
            }

            MLPrivilegesStarterKit.Stop();

            result = MLLocation.Start();

            if (!result.IsOk)
            {
                Debug.LogErrorFormat("Error: MLLocationStarterKit failed to start, Reason: {0}", result);
            }
            #endif

            return(result);
        }
 /// <summary>
 /// Start the MLLocation API.
 /// </summary>
 public static void Stop()
 {
     #if PLATFORM_LUMIN
     if (MLLocation.IsStarted)
     {
         MLLocation.Stop();
     }
     #endif
 }
Exemple #4
0
        /// <summary>
        /// Starts the MLLocation API and polls data if needed.
        /// </summary>
        private void StartupAPI()
        {
            MLLocation.Start();

            // Only want to place the pin once
            if (!_placedPin)
            {
                GetLocation();
            }
        }
Exemple #5
0
        void OnDestroy()
        {
            if (MLLocation.IsStarted)
            {
                MLLocation.Stop();
            }

            if (_privilegeRequester != null)
            {
                // Unregister event listener.
                _privilegeRequester.OnPrivilegesDone -= HandlePrivilegesDone;
            }
        }
Exemple #6
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;
            }
        }
    void OnApplicationPause(bool pauseStatus)
    {
        if (!pauseStatus)
        {
            if (!MLLocation.IsStarted)
            {
                MLLocation.Start();
            }

            MLCamera.Start();
            MLCamera.Connect();
            MLCamera.StartPreview();
        }
        else
        {
            OnDisable();
        }
    }
Exemple #8
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
            });
        }
    void OnEnable()
    {
        Logger.D(TAG, "Called OnEnable()...");

        // Start MagicLeap's Location service:
        if (!MLLocation.IsStarted)
        {
            MLLocation.Start();
        }

        // Needs a render Texture.
        Logger.D(TAG, "Calling Start to camera...");
        MLCamera.Start();
        Logger.D(TAG, "Calling Connect()...");
        MLCamera.Connect();

        Logger.D(TAG, "Calling StartPreview()...");
        MLCamera.StartPreview();

        Logger.D(TAG, "Setting texture sizes app side...");

        // Preview has fixed capture height and width. May need a prepare capture to do parameters not in preview.
        W = MLCamera.PreviewTextureWidth;
        H = MLCamera.PreviewTextureHeight;

        // Image width and height to send to face detection server
        ImageWidth  = 1440;
        ImageHeight = 1080;


        // Allocate space for render buffers:
        tmp = RenderTexture.GetTemporary(
            W,
            H,
            0,
            RenderTextureFormat.ARGB32,
            RenderTextureReadWrite.Linear);
        nt = new Texture2D(ImageWidth, ImageHeight, TextureFormat.ARGB32, false);
    }
Exemple #10
0
 /// <summary>
 /// Starts the MLLocation API and polls data if needed.
 /// </summary>
 private void StartupAPI()
 {
     MLLocation.Start();
     GetLocation();
     StartCoroutine(GetFineLocationLoop());
 }
        /// <summary>
        /// Gets the last valid location information.
        /// </summary>
        /// <param name="newLocation"></param>
        /// <param name="useFineLocation"></param>
        /// <returns></returns>
        public static MLResult GetLocation(out MLLocation.Location newLocation, bool useFineLocation = false)
        {
            MLResult result = useFineLocation ? MLLocation.GetLastFineLocation(out MLLocation.Location lastLocation) : MLLocation.GetLastCoarseLocation(out lastLocation);

            newLocation = lastLocation;
            return(result);
        }