Location APIs

chooseLocation

Open the map to choose a location.

Overview

my.chooseLocation opens a map interface that allows users to choose a specific location. The selected location's details, including longitude, latitude, name, and address, are returned through the success callback.

Sample Code

my.chooseLocation({
  success: (res) => {
    console.log(res);
    // Use the selected location data
    const selectedLocation = {
      name: res.name,
      address: res.address,
      latitude: res.latitude,
      longitude: res.longitude
    };
  },
  fail: (error) => {
    my.alert({ title: 'Failed to choose location' });
  },
});

Parameters

PropertyTypeRequiredDescription
successFunctionNoCallback function upon call success.
failFunctionNoCallback function upon call failure.
completeFunctionNoCallback function upon call completion (to be executed upon either call success or failure).

Success Callback Function

The incoming parameter is of the Object type with the following attributes:

PropertyTypeDescription
nameStringName of the selected location.
addressStringDetailed address of the selected location.
latitudeNumberLatitude of the selected location.
longitudeNumberLongitude of the selected location.

Error Code

ErrorDescriptionSolution
11Location permission not enabled.Prompt the user to enable location permission.
12Network abnormity, try again later.Prompt the user to check the current network.
13User cancelled the selection.-

Usage Notes

  • Requires location permission to be enabled
  • Users can search for locations within the map interface
  • The selected location includes both coordinates and address information
  • Users can cancel the selection, which will trigger the fail callback