以下是有关如何使用GeoWithin的示例代码,我的表单为https://github.com/jenssegers/laravel-mongodb
$users = User::where('location', 'geoWithin', [
'$geometry' => [
'type' => 'Polygon',
'coordinates' => [[
[
-0.1450383,
51.5069158,
],
[
-0.1367563,
51.5100913,
],
[
-0.1270247,
51.5013233,
],
[
-0.1450383,
51.5069158,
],
]],
],
]);
问题:我想使用自己的坐标,这些坐标存储为数组,但不知道如何在查询中实现它们。
这是我拥有的坐标的json,它位于Shop模型中。
"bounds" : [
[
0.4614208,
179.7144413
],
[
-0.812961,
178.5828495
],
[
-2.0210651,
-178.890295
],
[
0.2307123,
-177.5719357
]
],
这是到目前为止我尝试过的。不起作用。
$users = User::where('location', 'geoWithin', [
'$geometry' => [
'type' => 'Polygon',
'coordinates' => [$shop->bounds],
],
]);
非常感谢您的帮助。谢谢!
答案 0 :(得分:0)
library(purrr)
library(stringr)
dt1[, b := map(b, ~str_split(.x, ",") %>% unlist() %>% as.integer())]
dt1[, desc := map(b, ~dt2$desc[match(.x, dt2$code)])]
此代码有效,$cor 表示坐标