Пример #1
0
 /// <summary>
 /// The equality check to be used for comparing another object to this one.
 /// </summary>
 /// <param name="obj">The object to compare to this one with. </param>
 /// <returns>True if the the provided object is of the MLLocation.Location type and has matching field values.</returns>
 public override bool Equals(object obj)
 {
     if (obj is MLLocationData)
     {
         MLLocationData c = (MLLocationData)obj;
         return(this.Latitude == c.Latitude && this.Longitude == c.Longitude && this.PostalCode == c.PostalCode && this.HasPostalCode == c.HasPostalCode && this.Timestamp == c.Timestamp && this.Accuracy == c.Accuracy && this.HasAccuracy == c.HasAccuracy);
     }
     else
     {
         return(false);
     }
 }
Пример #2
0
        private MLResult GetLastLocationInternal(out MLLocationData outLocation, bool isFine)
        {
            // The automatic marshaling was not working properly for this structure. TimeStamp was always 0. To solve this
            // we use an IntPtr that has the proper default values set.
            NativeBindings.LocationNative location = NativeBindings.LocationNative.Create();
            MLResult.Code resultCode;

            IntPtr myPointer = Marshal.AllocHGlobal(Marshal.SizeOf(location));

            Marshal.StructureToPtr(location, myPointer, false);

            try
            {
                resultCode = isFine ? NativeBindings.MLLocationGetLastFineLocation(myPointer) : NativeBindings.MLLocationGetLastCoarseLocation(myPointer);

                if (resultCode != MLResult.Code.Ok)
                {
                    MLPluginLog.ErrorFormat("MLLocation.GetLastLocationInternal failed to get location. Reason: {0}", resultCode);
                    location.Latitude  = 0.0000f;
                    location.Longitude = 0.0000f;
                }

                location = (NativeBindings.LocationNative)Marshal.PtrToStructure(myPointer, typeof(NativeBindings.LocationNative));

                Marshal.FreeHGlobal(myPointer);

                MLResult finalResult = MLResult.Create(resultCode);

                outLocation = location.DataEx;

                if (finalResult.IsOk)
                {
                    if (isFine)
                    {
                        this.lastValidFineLocation = location.Data;
                    }
                    else
                    {
                        this.lastValidCoarseLocation = location.Data;
                    }
                }

                return(finalResult);
            }
            catch (EntryPointNotFoundException)
            {
                outLocation = new MLLocationData();
                MLPluginLog.Error("MLLocation.GetLastLocationInternal failed. Reason: API symbols not found.");
                return(MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLLocation.GetLastLocationInternal failed. Reason: API symbols not found."));
            }
        }
Пример #3
0
        public static MLResult GetLastCoarseLocation(out MLLocationData coarseLocation)
        {
            MLResult result = Instance.GetLastLocationInternal(out coarseLocation, true);

            return(result);
        }
Пример #4
0
        public static MLResult GetLastFineLocation(out MLLocationData fineLocation)
        {
            MLResult result = Instance.GetLastLocationInternal(out fineLocation, false);

            return(result);
        }