2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Runtime.InteropServices;
20 internal static partial class Interop
22 [DllImport(Libraries.MapService, EntryPoint = "maps_coordinates_get_latitude")]
23 internal static extern ErrorCode GetLatitude(this CoordinatesHandle /* maps_coordinates_h */ coordinates, out double latitude);
25 [DllImport(Libraries.MapService, EntryPoint = "maps_coordinates_get_longitude")]
26 internal static extern ErrorCode GetLongitude(this CoordinatesHandle /* maps_coordinates_h */ coordinates, out double longitude);
28 internal class CoordinatesHandle : SafeMapsHandle
30 [DllImport(Libraries.MapService, EntryPoint = "maps_coordinates_create")]
31 internal static extern ErrorCode Create(double latitude, double longitude, out IntPtr /* maps_coordinates_h */ coordinates);
33 [DllImport(Libraries.MapService, EntryPoint = "maps_coordinates_destroy")]
34 internal static extern ErrorCode Destroy(IntPtr /* maps_coordinates_h */ coordinates);
36 [DllImport(Libraries.MapService, EntryPoint = "maps_coordinates_clone")]
37 internal static extern ErrorCode Clone(IntPtr /* maps_coordinates_h */ origin, out IntPtr /* maps_coordinates_h */ cloned);
39 internal double Latitude
41 get { return NativeGet<double>(this.GetLatitude); }
44 internal double Longitude
46 get { return NativeGet<double>(this.GetLongitude); }
49 internal CoordinatesHandle(IntPtr handle, bool needToRelease) : base(handle, needToRelease, Destroy)
53 internal CoordinatesHandle(double latitude, double longitude) : this(IntPtr.Zero, true)
55 Create(latitude, longitude, out handle).ThrowIfFailed("Failed to create native handle");
58 internal static CoordinatesHandle CloneFrom(IntPtr nativeHandle)
61 Clone(nativeHandle, out handle).ThrowIfFailed("Failed to clone native handle");
62 return new CoordinatesHandle(handle, true);
65 internal static CoordinatesHandle Create(IntPtr nativeHandle)
67 return new CoordinatesHandle(nativeHandle, true);
70 public override string ToString()
72 return $"[{Latitude}, {Longitude}]";