Supported platforms: Mini Program 2.6.3, Cloud Functions
Constructs a "line" for geographic locations. A line consists of two or more points connected in order.
Parameters
points: GeoPoint[]
Array of "points"
Return Value
GeoPoint
Index
If the field storing geographic location information is subject to query operations, a geographic location index must be created for that field.
Example Code
db.collection('todos').add({
data: {
description: 'eat an apple',
location: db.Geo.LineString([
db.Geo.Point(113, 23),
db.Geo.Point(120, 50),
// ... Optional additional points
])
}
}).then(console.log).catch(console.error)
In addition to constructing a LineString using the API, you can also use the equivalent JSON representation of a Line (LineString) in GeoJSON. Its format is as follows:
{
"type": "LineString",
"coordinates": [
[p1_lng, p1_lat],
[p2_lng, p2_lng]
// ... Optional additional points
]
}
Example Code
db.collection('todos').add({
data: {
description: 'eat an apple',
location: {
type: 'LineString',
coordinates: [
[113, 23],
[120, 50]
]
}
}
}).then(console.log).catch(console.error)