You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Retrieves the distance between 2 geometry objects.
39
+
Retrieves the distance between 2 geometry objects. Uses [ST_Distance](https://dev.mysql.com/doc/refman/8.0/en/spatial-relation-functions-object-shapes.html#function_st-distance)
Filters records by distance. Uses [ST_Distance](https://dev.mysql.com/doc/refman/8.0/en/spatial-relation-functions-object-shapes.html#function_st-distance)
63
70
64
-
| parameter name | type
71
+
| parameter name | type
65
72
| ------------------ | --------------------
66
-
| `$column` | `string`
73
+
| `$column` | `string`
67
74
| `$geometryOrColumn` | `Geometry \| string`
68
75
| `$operator` | `string`
69
76
| `$value` | `int \| float`
70
77
71
78
<details><summary>Example</summary>
72
79
73
80
```php
81
+
Place::create(['location' => new Point(0, 0)]);
82
+
Place::create(['location' => new Point(100, 100)]);
83
+
84
+
$placesCountWithinDistance = Place::query()
85
+
->whereDistance('location', new Point(1, 1), '<', 1.5)
86
+
->count();
87
+
88
+
echo $placesCountWithinDistance; // 1
89
+
```
90
+
</details>
91
+
92
+
### orderByDistance
93
+
94
+
Orders records by distance. Uses [ST_Distance](https://dev.mysql.com/doc/refman/8.0/en/spatial-relation-functions-object-shapes.html#function_st-distance)
->whereDistance('point', new Point(1, 1), '<', 10)
114
+
$places = Place::query()
115
+
->orderByDistance('location', new Point(1, 1), 'desc')
116
+
->get();
117
+
118
+
echo $places[0]->name; // second
119
+
echo $places[1]->name; // first
120
+
```
121
+
</details>
122
+
123
+
### withDistanceSphere
124
+
125
+
Retrieves the spherical distance between 2 geometry objects. Uses [ST_Distance_Sphere](https://dev.mysql.com/doc/refman/8.0/en/spatial-convenience-functions.html#function_st-distance-sphere)
Filters records by spherical distance. Uses [ST_Distance_Sphere](https://dev.mysql.com/doc/refman/8.0/en/spatial-convenience-functions.html#function_st-distance-sphere)
156
+
157
+
| parameter name | type
158
+
| ------------------ | --------------------
159
+
| `$column` | `string`
160
+
| `$geometryOrColumn` | `Geometry \| string`
161
+
| `$operator` | `string`
162
+
| `$value` | `int \| float`
163
+
164
+
<details><summary>Example</summary>
165
+
166
+
```php
167
+
Place::create(['location' => new Point(0, 0)]);
168
+
Place::create(['location' => new Point(100, 100)]);
169
+
170
+
$placesCountWithinDistance = Place::query()
171
+
->whereDistance('location', new Point(1, 1), '<', 160000)
172
+
->count();
173
+
174
+
echo $placesCountWithinDistance; // 1
175
+
```
176
+
</details>
177
+
178
+
### orderByDistance
179
+
180
+
Orders records by spherical distance. Uses [ST_Distance_Sphere](https://dev.mysql.com/doc/refman/8.0/en/spatial-convenience-functions.html#function_st-distance-sphere)
0 commit comments