uni-app 阿里云地理聚合函数

uni-app 阿里云地理聚合函数

操作步骤:

1

预期结果:

1

实际结果:

1

bug描述:

const db = uniCloud.database()  

const a = new this.db.Geo.LineString([  
    new db.Geo.Point(113.94566, 22.52932),  
    new db.Geo.Point(113.9468, 22.5342),  
    new db.Geo.Point(113.9510, 22.5378)  
])  

console.log("a", a)

上面生成的这个LineString数据,a打印的结果是

{
    "points": [{  
        "longitude": 113.94566,  
        "latitude": 22.52932  
    }, {  
        "longitude": 113.9468,  
        "latitude": 22.5342  
    }, {  
        "longitude": 113.951,  
        "latitude": 22.5378  
    }]  
}

把a的结果存到数据库中,得到的数据结果又是

route_line:{  
coordinates:[[113.94566,22.52932],.....],  
"type": "LineString"  
}

就是说咱们能不能把数据做的统一些?


更多关于uni-app 阿里云地理聚合函数的实战教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

Geo.LineString API 是方便用户定义经纬度,实际上数据格式以数据库存储的为准。数据库存储格式为MongoDB定义的数据结构,使用MongoDB数据结构也可以正常插入。

更多关于uni-app 阿里云地理聚合函数的实战教程也可以访问 https://www.itying.com/category-93-b0.html


这是一个关于uni-app阿里云地理数据格式统一性的问题。从代码和截图来看,确实存在Geo数据在不同环节格式不一致的情况:

  1. 控制台打印的LineString对象显示为包含points数组的对象格式
  2. 实际存储到数据库后变为标准的GeoJSON格式(带coordinates和type字段)

这是阿里云uniCloud的地理数据处理机制导致的差异。建议在实际使用时:

  1. 查询时直接使用GeoJSON标准格式处理数据
  2. 如果需要在业务代码中使用统一格式,可以在查询后手动转换:
// 查询后转换格式
const result = await db.collection('your_collection').get()
const lineString = {
  points: result.data[0].route_line.coordinates.map(coord => ({
    longitude: coord[0],
    latitude: coord[1]
  }))
}
回到顶部