Пример #1
0
 // Use this for initialization
 void Start()
 {
     if (m_state == GPS_STATE.READY)
     {
         m_state = GPS_STATE.LOCATING;
         StartCoroutine(StartGPSService());
     }
 }
        /// <summary>
        /// Sets the current location.
        /// </summary>
        /// <param name="latitude">Current latitude in WGS84 decimal degrees.</param>
        /// <param name="longitude">Current longitude in WGS84 decimal degrees.</param>
        /// <param name="velocity">Current horizontal velocity in meters/second.</param>
        /// <param name="error">Estimated horizontal positional error in meters (95% confidence level).</param>
        /// <remarks>
        /// When the TrackingState is packed into a byte array to be used as an RTT message valuse may be trncated as follows: -
        /// Latitude/Longitude will be truncated to single presision floating point numbers.
        /// The error values is packed into 6 bits in 3 meter increments giving a maximum value of 208 meters.
        /// </remarks>
        public void SetLocation(double latitude, double longitude, double velocity, uint error)
        {
            mLat      = latitude;
            mLong     = longitude;
            mVelocity = velocity;
            mError    = error;

            mGPSState = (error > mAcceptableError) ? GPS_STATE.BAD_FIX : GPS_STATE.GOOD_FIX;

            // log bad fixes
            if (mGPSState == GPS_STATE.BAD_FIX)
            {
                CNXLog.ErrorFormat("GPS Precision {0}, {1}, {2}M", latitude, longitude, error * 3);
            }
        }
Пример #3
0
    IEnumerator StartGPSService()
    {
        // Input.location 用于访问设备的位置属性(手持设备), 静态的LocationService位置
        // LocationService.isEnabledByUser 用户设置里的定位服务是否启用
        if (!Input.location.isEnabledByUser)
        {
            m_state = GPS_STATE.NOT_ENABLE_BY_USER;
            yield break;
        }

        // LocationService.Start() 启动位置服务的更新,最后一个位置坐标会被使用
        Input.location.Start(100.0f, 100.0f);

        int maxWait = 5;

        while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
        {
            // 暂停协同程序的执行(1秒)
            yield return(new WaitForSeconds(1));

            maxWait--;
        }

        //超时
        if (maxWait < 1)
        {
            m_state = GPS_STATE.TIMEOUT;
            yield break;
        }

        //失败
        if (Input.location.status == LocationServiceStatus.Failed)
        {
            m_state = GPS_STATE.FAIL;
            yield break;
        }
        else
        {
            m_v2LatLng.x = Input.location.lastData.latitude;
            m_v2LatLng.y = Input.location.lastData.longitude;
            m_state      = GPS_STATE.SUC;
            yield break;
        }
    }
Пример #4
0
 /// <summary>
 /// 停止定位
 /// </summary>
 void StopGPS()
 {
     m_state = GPS_STATE.NONE;
     Input.location.Stop();
 }
Пример #5
0
 /// <summary>
 /// 启动定位
 /// </summary>
 public void StartGPS()
 {
     m_state = GPS_STATE.READY;
 }