Since version 26.0.0, the function of querying the map areas that are not downloaded based on an array of longitude and latitude coordinates is supported.
The offline map allows users to download map data of a specified area in advance so that they can use map functions properly when there is no network connection or the network connection is poor.
| API | Description |
|---|---|
| getRecommendedCityIdsByLatLngs(context: common.Context, latlngs: mapCommon.LatLng[]): Promise<string[]> | Queries offline map areas that are not downloaded on the device based on an array of longitude and latitude coordinates. |
import { offlineMapData } from '@kit.MapKit';
import { mapCommon } from '@kit.MapKit'; try {
// Longitude and latitude array.
let latLngArr: mapCommon.LatLng[] = [{
latitude: 49.5,
longitude: 3.5
}, {
latitude: 49.5,
longitude: 4.5
}, {
latitude: 50.5,
longitude: 4.5
}, {
latitude: 51.5,
longitude: 4.5
}];
// Query the map areas that are not downloaded on the device based on an array of longitude and latitude coordinates.
let resArray: string[] = await offlineMapData.getRecommendedCityIdsByLatLngs(
this.getUIContext().getHostContext(), latLngArr);
console.info(`resArray: ${JSON.stringify(resArray)}`);
} catch (e) {
console.error(`code:${e.code}, message:${e.message}`);
}