my.chooseLocation

Open the built-in map to choose a location.

Sample codes

JSON

copy
// API-DEMO page/API/choose-location/choose-location.json
{
    "defaultTitle": "Choose Location"
}

AXML

copy
<!-- API-DEMO page/API/choose-location/choose-location.axml-->
<view class="page">
  <view class="page-section">
    <view class="page-section-demo">
      <text>Longitude:</text>
      <input value="{{longitude}}"></input>
    </view>
    <view class="page-section-demo">
      <text>Latitude:</text>
      <input value="{{latitude}}"></input>
    </view>
    <view class="page-section-demo">
      <text>Name:</text>
      <input value="{{name}}"></input>
    </view>
    <view class="page-section-demo">
      <text>Address:</text>
      <input value="{{address}}"></input>
    </view>    
    <view class="page-section-btns">
      <view onTap="chooseLocation">choose Location</view>
    </view>
  </view>
</view>

JavaScript

copy
// API-DEMO page/API/choose-location/choose-location.js
Page({
  data: {
    longitude: '103.873834',
    latitude: '1.355572',
    name: 'Serangoon Stadium',
    address: '33 Yio Chu Kang Rd, Singapore',
  },
  chooseLocation() {
    var that = this
    my.chooseLocation({
         success:(res)=>{
          console.log(JSON.stringify(res))
          that.setData({
            longitude:res.longitude,
            latitude:res.latitude,
            name:res.name,
            address:res.address
          })
        },
        fail:(error)=>{
          my.alert({content: 'failed:'+JSON.stringify(error)});
        },
    });
    },
})

ACSS

copy
/* API-DEMO page/API/choose-location/choose-location.acss */
.page-body-info {
  height: 250rpx;
}
.page-body-text-location {
  display: flex;
  font-size: 50rpx;
}
.page-body-text-location text {
  margin: 10rpx;
}
.page-section-location-text{
    color: #49a9ee;
}

Parameters

Property

Type

Required

Description

success

Function

No

The callback method that indicates a successful call.

fail

Function

No

The callback method that indicates a failed call.

complete

Function

No

The callback method that indicates the call is completed (this will be executed regardless of whether the call succeeds or fails).

Success Callback Function

Property

Type

Description

name

String

The location.

address

String

The detailed address of the location.

latitude

Number

The latitude that is expressed by a floating-point number. The value ranges from -90 to +90, and the negative number means south latitude. 

longitude

Number

The longitude that is expressed by a floating-point number. The value ranges from -180 to +180, and the negative number means west longitude. 

provinceName

String

The province.

cityName

String

The city.