跳到主要内容

bn.chooseLocation

chooseLocation(options): Promise<ChooseLocationResponse>

description Open the map and select the location

example

  // To get the user's location by api In the mini program, the developer needs to firstly request the user for the authorization.
bn
.authorize({ scope: 'scope.userLocation' })
.then(res => console.log(`[authorize] SUCCESS:`, res))
.catch(err => console.log(`[authorize] ERROR:`, err))

bn
.getLocation({ type: 'wgs84', altitude: false })
.then(res =>
bn.showModal({
title: 'getLocation',
content: 'success' + JSON.stringify(res),
}),
)
.catch(error =>
bn.showModal({
title: 'getLocation',
content: 'fail' + JSON.stringify(error),
}),
)

// Please note: the user may disable the location permissions in the open settings of the mini program. The developer can use getSetting api to have a check.
const res = await bn.getSetting()
console.log(res.authSetting['scope.userLocation']) // boolean
// and also, the developer can open the permission panel for user to enable the setting
await bn.openSetting()

Parameters

NameTypeDescription
optionsChooseLocationOptionsChoose location options

Returns

Promise<ChooseLocationResponse>

Location information

ChooseLocationOptions

Ƭ ChooseLocationOptions: Object

Type declaration

NameTypeDescription
latitude?numberTarget latitude
longitude?numberTarget longitude

ChooseLocationResponse

Ƭ ChooseLocationResponse: Object

Type declaration

NameTypeDescription
latitudenumberLatitude, range -90 ~ 90. The negative number indicates latitude south. use gcj02 NBS coordinate system
longitudenumberLongitude, range -180 ~ 180. The negative numbers indicates west longitude. use gcj02 NBS coordinate system
namestringLocation name
addressstringDetailed address