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