my.openLocation

View the location on the built-in map.

Sample codes

copy
// API-DEMO page/API/open-location/open-location.json
{
    "defaultTitle": "Open Location"
}
copy
<!-- API-DEMO page/API/open-location/open-location.axml-->
<view class="page">
  <view class="page-section">
    <view class="page-section-demo">
      <text>Longitude</text>
      <input type="text" disabled="{{true}}" value="{{longitude}}" name="longitude"></input>
    </view>
    <view class="page-section-demo">
      <text>Latitude</text>
      <input type="text" disabled="{{true}}"  value="{{latitude}}" name="latitude"></input>
    </view>
    <view class="page-section-demo">
      <text>Name</text>
      <input type="text" disabled="{{true}}"  value="{{name}}" name="name"></input>
    </view>
    <view class="page-section-demo">
      <text>Address</text>
      <input type="text" disabled="{{true}}"  value="{{address}}" name="address"></input>
    </view>
    <view class="page-section-btns">
      <view type="primary" formType="submit" onTap="openLocation">open location</view>
    </view>
  </view>
</view>
copy
// API-DEMO page/API/open-location/open-location.js
Page({
  data: {
    longitude: '103.873834',
    latitude: '1.355572',
    name: 'Serangoon Stadium',
    address: '33 Yio Chu Kang Rd, Singapore',
  },

  openLocation() {
    my.openLocation({
      longitude: this.data.longitude,
      latitude: this.data.latitude,
      name: this.data.name,
      address: this.data.address,
    })
  }
})

Parameters

Property

Type

Required

Description

longitude

String

Yes

The longitude.

latitude

String

Yes

The latitude.

name

String

Yes

The location.

address

String

Yes

The detailed address of the location.

scale

Number

No

The zoom level. The value ranges from 3 to 19 and is 15 by default.

success

Function

No

The callback method indicates a successful call.

fail

Function

No

The callback method 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).