1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/** 17 * @syscap SystemCapability.Location.Location.Lite 18 */ 19export interface GeolocationResponse { 20 /** 21 * Longitude. 22 * @since 3 23 */ 24 longitude: number; 25 26 /** 27 * Latitude. 28 * @since 3 29 */ 30 latitude: number; 31 32 /** 33 * Altitude. 34 * @since 3 35 */ 36 altitude: number; 37 38 /** 39 * Location accuracy. 40 * @since 3 41 */ 42 accuracy: number; 43 44 /** 45 * Time when the location is obtained. 46 * @since 3 47 */ 48 time: number; 49} 50 51/** 52 * @syscap SystemCapability.Location.Location.Lite 53 * @permission ohos.permission.LOCATION 54 */ 55export interface GetLocationOption { 56 /** 57 * Timeout duration, in milliseconds. 58 * For the rich device, the default value is 30000. 59 * For the lite wearable device, the default value is 180000. 60 * The timeout duration is necessary in case no result is returned if the request to obtain the geographic location is rejected for the lack of the required permission, weak positioning signal, or incorrect location settings. After the timeout duration expires, the fail function will be called. 61 * The value is a 32-digit positive integer. 62 * If the value set is less than or equal to 0, the default value will be used. 63 * @since 3 64 */ 65 timeout?: number; 66 67 /** 68 * Coordinate system type. Available types can be obtained using getSupportedCoordTypes. 69 * The default type is wgs84. 70 * @since 3 71 */ 72 coordType?: string; 73 74 /** 75 * Called when the geographic location is obtained. 76 * @since 3 77 */ 78 success?: (data: GeolocationResponse) => void; 79 80 /** 81 * Called when the location types fail to be obtained 82 * @since 3 83 */ 84 fail?: (data: string, code: number) => void; 85 86 /** 87 * Called when the execution is completed. 88 * @since 3 89 */ 90 complete?: () => void; 91} 92 93/** 94 * @syscap SystemCapability.Location.Location.Lite 95 */ 96export interface GetLocationTypeResponse { 97 /** 98 * @since 3 99 */ 100 types: Array<string>; 101} 102 103/** 104 * @syscap SystemCapability.Location.Location.Lite 105 */ 106export interface GetLocationTypeOption { 107 /** 108 * Called when the location types are obtained. 109 * @since 3 110 */ 111 success?: (data: GetLocationTypeResponse) => void; 112 113 /** 114 * Called when the location types fail to be obtained. 115 * @since 3 116 */ 117 fail?: (data: string, code: number) => void; 118 119 /** 120 * Called when the execution is completed. 121 * @since 3 122 */ 123 complete?: () => void; 124} 125 126/** 127 * @syscap SystemCapability.Location.Location.Lite 128 * @permission ohos.permission.LOCATION 129 */ 130export interface SubscribeLocationOption { 131 /** 132 * Coordinate system type. Available types can be obtained using getSupportedCoordTypes. 133 * The default type is wgs84. 134 * @since 3 135 */ 136 coordType?: string; 137 138 /** 139 * Called whenever the geographical location changes. 140 * @since 3 141 */ 142 success: (data: GeolocationResponse) => void; 143 144 /** 145 * Called when the listening fails. 146 * @since 3 147 */ 148 fail?: (data: string, code: number) => void; 149} 150 151/** 152 * @syscap SystemCapability.Location.Location.Lite 153 */ 154export default class Geolocation { 155 /** 156 * Obtains the geographic location. 157 * @permission ohos.permission.LOCATION 158 * @param options Options. 159 */ 160 static getLocation(options?: GetLocationOption): void; 161 162 /** 163 * Obtains the location types supported by the system. 164 * @param options Options. 165 */ 166 static getLocationType(options?: GetLocationTypeOption): void; 167 168 /** 169 * Listens to the geographical location. If this method is called multiple times, the last call takes effect. 170 * @permission ohos.permission.LOCATION 171 * @param options Options. 172 */ 173 static subscribe(options: SubscribeLocationOption): void; 174 175 /** 176 * Cancels listening to the geographical location. 177 * @permission ohos.permission.LOCATION 178 */ 179 static unsubscribe(): void; 180 181 /** 182 * Obtains the supported coordinate system types. 183 * @returns A string array of the supported coordinate system types, for example, ['wgs84']. 184 */ 185 static getSupportedCoordTypes(): Array<string>; 186} 187