1# @system.geolocation (Geolocation)
2
3The **geolocation** module provides only basic functions such as GNSS positioning and network positioning.
4
5> **NOTE**
6> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version.
7> - The APIs provided by this module are no longer maintained since API version 9. You are advised to use [geoLocationManager](js-apis-geoLocationManager.md) instead.
8
9
10## Modules to Import
11
12```
13import geolocation from '@system.geolocation';
14```
15
16
17## Required Permissions
18
19ohos.permission.LOCATION
20
21
22## geolocation.getLocation<sup>(deprecated)</sup>
23
24getLocation(options?: GetLocationOption): void
25
26Obtains the geographic location.
27
28> **NOTE**<br>
29> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getCurrentLocation](js-apis-geoLocationManager.md#geolocationmanagergetcurrentlocation).
30
31**Required permissions**: ohos.permission.LOCATION
32
33**System capability**: SystemCapability.Location.Location.Lite
34
35**Parameters**
36
37| Name| Type| Mandatory| Description|
38| -------- | -------- | -------- | -------- |
39| options | [GetLocationOption](#getlocationoptiondeprecated) | No| Options of a single location request.|
40
41**Example**
42
43```
44export default {
45  getLocation() {
46    geolocation.getLocation({
47      success: function(data) {
48        console.info('success get location data. latitude:' + data.latitude);
49      },
50      fail: function(data, code) {
51        console.info('fail to get location. code:' + code + ', data:' + data);
52      }
53    });
54  }
55}
56```
57
58
59## geolocation.getLocationType<sup>(deprecated)</sup>
60
61getLocationType(options?: GetLocationTypeOption): void
62
63Obtains the supported location types.
64
65> **NOTE**<br>
66> This API is deprecated since API version 9. The location subsystem supports only two location types: GNSS positioning and network positioning. No APIs will be provided to query the supported location types.
67
68**System capability**: SystemCapability.Location.Location.Lite
69
70**Parameters**
71
72| Name| Type| Mandatory| Description|
73| -------- | -------- | -------- | -------- |
74| options | [GetLocationTypeOption](#getlocationtypeoptiondeprecated) | No| Callback used to return the result.|
75
76**Example**
77
78```
79export default {
80  getLocationType() {
81    geolocation.getLocationType({
82      success: function(data) {
83        console.info('success get location type:' + data.types[0]);
84      },
85      fail: function(data, code) {
86        console.info('fail to get location. code:' + code + ', data:' + data);
87       },
88     });
89  },
90}
91```
92
93
94## geolocation.subscribe<sup>(deprecated)</sup>
95
96subscribe(options: SubscribeLocationOption): void
97
98Listens to the geographic location. If this method is called multiple times, the last call takes effect.
99
100> **NOTE**<br>
101> This API is deprecated since API version 9. You are advised to use [geoLocationManager.on('locationChange')](js-apis-geoLocationManager.md#geolocationmanageronlocationchange).
102
103**Required permissions**: ohos.permission.LOCATION
104
105**System capability**: SystemCapability.Location.Location.Lite
106
107**Parameters**
108
109| Name| Type| Mandatory| Description|
110| -------- | -------- | -------- | -------- |
111| options | [SubscribeLocationOption](#subscribelocationoptiondeprecated) | Yes| Options for continuous location.|
112
113**Example**
114
115```
116export default {
117  subscribe() {
118    geolocation.subscribe({
119      success: function(data) {
120        console.info('get location. latitude:' + data.latitude);
121      },
122      fail: function(data, code) {
123        console.info('fail to get location. code:' + code + ', data:' + data);
124      },
125    });
126  },
127}
128```
129
130
131## geolocation.unsubscribe<sup>(deprecated)</sup>
132
133unsubscribe(): void
134
135Cancels listening to the geographic location.
136
137> **NOTE**<br>
138> This API is deprecated since API version 9. You are advised to use [geoLocationManager.off('locationChange')](js-apis-geoLocationManager.md#geolocationmanagerofflocationchange).
139
140**Required permissions**: ohos.permission.LOCATION
141
142**System capability**: SystemCapability.Location.Location.Lite
143
144**Example**
145
146```
147export default {
148  unsubscribe() {
149    geolocation.unsubscribe();
150  }
151}
152```
153
154
155## geolocation.getSupportedCoordTypes<sup>(deprecated)</sup>
156
157getSupportedCoordTypes(): Array&lt;string&gt;
158
159Obtains coordinate system types supported by the device.
160
161> **NOTE**<br>
162> This API is deprecated since API version 9. The location subsystem supports only the WGS-84 coordinate system. No APIs will be provided to query the supported coordinate system types.
163
164**System capability**: SystemCapability.Location.Location.Lite
165
166**Return value**
167
168| Type| Not empty| Description|
169| -------- | -------- | -------- |
170| Array&lt;string&gt; | Yes| Coordinate system types, for example, **[wgs84, gcj02]**.|
171
172**Example**
173
174```
175export default {
176  getSupportedCoordTypes() {
177    var types = geolocation.getSupportedCoordTypes();
178  },
179}
180```
181
182## GetLocationOption<sup>(deprecated)</sup>
183
184Options of a single location request.
185
186> **NOTE**<br>
187> This API is deprecated since API version 9. You are advised to use [geoLocationManager.CurrentLocationRequest](js-apis-geoLocationManager.md#CurrentLocationRequest).
188
189**Required permissions**: ohos.permission.LOCATION
190
191**System capability**: SystemCapability.Location.Location.Lite
192
193| Name| Type| Mandatory| Description|
194| -------- | -------- | -------- | -------- |
195| timeout | number | No| Timeout duration, in ms. The default value is **30000**.<br>The timeout duration is necessary in case 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.<br>The value is a 32-digit positive integer. If the specified value is less than or equal to **0**, the default value will be used.|
196| coordType | string | No| Coordinate system type. Available types can be obtained by **getSupportedCoordTypes**. The default type is **wgs84**.|
197| success | (data: [GeolocationResponse](#geolocationresponsedeprecated)) => void | No| Called when API call is successful.|
198| fail |  (data: string, code: number) => void | No| Called when API call has failed. **data** indicates the error information, and **code** indicates the error code.|
199| complete | () => void | No| Called when API call is complete.|
200
201**Return value of fail()**
202
203| Error Code| Description|
204| -------- | -------- |
205| 601 | Failed to obtain the required permission because the user rejected the request.|
206| 602 | Permission not declared.|
207| 800 | Operation times out due to a poor network condition or GNSS unavailability.|
208| 801 | System location disabled.|
209| 802 | API called again while the previous execution result is not returned yet.|
210
211## GeolocationResponse<sup>(deprecated)</sup>
212
213Defines the location information, including the longitude, latitude, and location precision.
214
215> **NOTE**<br>
216> This API is deprecated since API version 9. You are advised to use [geoLocationManager.Location](js-apis-geoLocationManager.md#location).
217
218**System capability**: SystemCapability.Location.Location.Lite
219
220| Name| Type| Read Only| Optional| Description|
221| -------- | -------- | -------- | -------- | -------- |
222| longitude | number | No| No| Longitude.|
223| latitude | number | No| No| Latitude.|
224| altitude | number | No| No| Altitude.|
225| accuracy | number | No| No| Location accuracy.|
226| time | number | No| No| Time when the location is obtained.|
227
228## GetLocationTypeOption<sup>(deprecated)</sup>
229
230Defines the location type option, which holds the callback function used to return the query result.
231
232> **NOTE**<br>
233> This API is deprecated since API version 9.
234
235**System capability**: SystemCapability.Location.Location.Lite
236
237| Name| Type| Mandatory| Description|
238| -------- | -------- | -------- | -------- |
239| success | (data: [GetLocationTypeResponse](#getlocationtyperesponsedeprecated)) => void | No| Called when API call is successful.|
240| fail | (data: string, code: number) => void | No| Called when API call has failed.|
241| complete | () => void | No| Called when API call is complete.|
242
243## GetLocationTypeResponse<sup>(deprecated)</sup>
244
245Defines the list of location types supported by the current device
246
247> **NOTE**<br>
248> This API is deprecated since API version 9.
249
250**System capability**: SystemCapability.Location.Location.Lite
251
252| Name| Type| Read Only| Optional| Description|
253| -------- | -------- | -------- | -------- | -------- |
254| types | Array&lt;string&gt; | No| No| Available location types, ['gps', 'network']|
255
256## SubscribeLocationOption<sup>(deprecated)</sup>
257
258Defines the options for continuous location.
259
260> **NOTE**<br>
261> This API is deprecated since API version 9. You are advised to use [geoLocationManager.CurrentLocationRequest](js-apis-geoLocationManager.md#locationrequest).
262
263**Required permissions**: ohos.permission.LOCATION
264
265**System capability**: SystemCapability.Location.Location.Lite
266
267| Name| Type| Mandatory| Description|
268| -------- | -------- | -------- | -------- |
269| coordType | string | No| Coordinate system type. Available types can be obtained by **getSupportedCoordTypes**. The default type is **wgs84**.|
270| success | (data: [GeolocationResponse](#geolocationresponsedeprecated)) => void | Yes| Called when the geographic location changes.|
271| fail | (data: string, code: number) => void | No| Called when API call has failed.|
272
273**Return value of fail()**
274
275| Error Code| Description|
276| -------- | -------- |
277| 601 | Failed to obtain the required permission because the user rejected the request.|
278| 602 | Permission not declared.|
279| 801 | System location disabled.|
280