我可以使用 2dsphere 索引计算 MongoDB 中从点到点的距离。
但是,现在我需要计算从给定点到多边形的距离。
我正在使用以下代码:
Document commandNoIntersect = new Document("geoNear", "Location")
.append("near", new com.mongodb.client.model.geojson.Point(new Position(Longitude, Latitude)))
.append("spherical", true)
.append("query", new Document(new Document("location", locationId)))
.append("distanceMultiplier", 0.001);
database.runCommand(commandNoIntersect);
我的 2dsphere 索引是多边形的坐标。结果与点对点距离不一致。
感谢您的反馈,