Geolocation: Mobile Geolocation Service

更新时间:
2024-06-19
下载文档

Geolocation: Mobile Geolocation Service

The geo module provides many interfaces for applications to access geographic locations.

Developers can determine whether these interfaces work in the EdgerOS mobile App environment through the following code:

edger.env().then(data => {
  if (data.env === 'edgerapp') {
    // We work in EdgerOS mobile App environment.
  }
}).catch(error => {
  console.error(error);
});

Functions

edger.geo.address(latitude, longitude)

Generate address information based on latitude and longitude.

  • latitude {Number} The latitude of geographic location.
  • longitude {Number} The longitude of geographic location.
  • Returns: {Promise} Promise object.

Get a geographic location object of promise type. The geographic location object includes:

  • address {String} Geo-transformed address result.

Example

const latitude = 39.910925;
const longitude = 116.413384;

edger.geo.address(latitude, longitude).then((payload) => {
  const { address } = payload
  console.log("Geo-transformed address result:", address);
}).catch((error) => {
  console.error(error);
});

async / await

async function geoAddress() {
  try {
    await edger.geo.address(latitude, longitude);
    const { address } = payload;
    console.log("Geo-transformed address result:", address);
  } catch (error) {
    console.error(error);
  }
}
文档内容是否对您有所帮助?
有帮助
没帮助