微信小程序云開發(fā)服務(wù)端數(shù)據(jù)庫API 地理位置構(gòu)造器

2022-05-12 16:20 更新

db.Geo

該對(duì)象上含有地理位置構(gòu)造器。

擁有字段如下:

字段說明
Point地理位置點(diǎn)

db.Geo.Point

構(gòu)造一個(gè)地理位置點(diǎn)??捎糜诓樵儣l件、更新字段值或新增記錄時(shí)的字段值。

方法簽名如下:

function Point(longitude: number, latitude: number): Point

方法接受兩個(gè)必填參數(shù),第一個(gè)是經(jīng)度(longitude),第二個(gè)是緯度(latitude),務(wù)必注意順序

示例代碼

const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()
exports.main = async (event, context) => {
  try {
    return await db.collection('todos').add({
      description: 'eat an apple',
      location: new db.Geo.Point(113, 23)
    })
  } catch(e) {
    console.error(e)
  }
}
以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)