質問編集履歴
2
質問内容の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -99,3 +99,85 @@
|
|
99
99
|
activerecord (= 4.2.3)
|
100
100
|
|
101
101
|
```
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
### 追記:
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
https://github.com/fjl82/activerecord-mysql2spatial-adapter/tree/activerecord-4.2
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
4.2 用のブランチがあったので Gemfile で指定してインストールするとインストールできました
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
user.rb に
|
118
|
+
|
119
|
+
```
|
120
|
+
|
121
|
+
# By default, use the GEOS implementation for spatial columns.
|
122
|
+
|
123
|
+
self.rgeo_factory_generator = RGeo::Geos.method(:factory)
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
# But use a geographic implementation for the :latlon column.
|
128
|
+
|
129
|
+
set_rgeo_factory_for_column(:user_location_center, RGeo::Geographic.spherical_factory)
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
```
|
134
|
+
|
135
|
+
とかいてみたところエラーが出なかったので使えてるんだと思うのですが使い方がわかりません
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
以下のようなマイグレーションで user モデルの location というカラムを point type にしたのですが
|
140
|
+
|
141
|
+
```
|
142
|
+
|
143
|
+
create_table :users do |t|
|
144
|
+
|
145
|
+
t.column :location, :point, null: false
|
146
|
+
|
147
|
+
```
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
user.rb で
|
152
|
+
|
153
|
+
```
|
154
|
+
|
155
|
+
before_save :set_columns
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
def set_columns
|
160
|
+
|
161
|
+
self.location = "POINT(137, 39)"
|
162
|
+
|
163
|
+
puts self.location
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
```
|
168
|
+
|
169
|
+
とポイント型のデータを挿入するテストコードをかいてみたのですが
|
170
|
+
|
171
|
+
puts の結果も SQL のログも値が0になってしまいます
|
172
|
+
|
173
|
+
```
|
174
|
+
|
175
|
+
0
|
176
|
+
|
177
|
+
Mysql2::Error: Cannot get geometry object from data you send to the GEOMETRY field: INSERT INTO `users` (`location`, `created_at`, `updated_at`) VALUES (0, '2019-03-11 04:49:52', '2019-03-11 04:49:52')):
|
178
|
+
|
179
|
+
```
|
180
|
+
|
181
|
+
activerecord-mysql2spatial-adapter
|
182
|
+
|
183
|
+
の使い方がわかる方いらっしゃったら教えていただけないでしょうか
|
1
質問内容の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -53,3 +53,49 @@
|
|
53
53
|
geometry を使った検索自体は別のフレームワークでやるので
|
54
54
|
|
55
55
|
Rails からはあるカラムに lat, lng => Point の出し入れができるだけでいいのですが…
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
###追記:
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
よく検索にひっかかる armg と activerecord-mysql2spatial-adapter
|
66
|
+
|
67
|
+
がいずれも Rails 4.2.3 で使えません
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
```
|
72
|
+
|
73
|
+
In Gemfile:
|
74
|
+
|
75
|
+
armg was resolved to 0.7.1, which depends on
|
76
|
+
|
77
|
+
activerecord (~> 5)
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
rails (= 4.2.3) was resolved to 4.2.3, which depends on
|
82
|
+
|
83
|
+
activerecord (= 4.2.3)
|
84
|
+
|
85
|
+
```
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
```
|
90
|
+
|
91
|
+
activerecord-mysql2spatial-adapter was resolved to 0.5.2, which depends on
|
92
|
+
|
93
|
+
activerecord (< 4.2, >= 4.0)
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
rails (= 4.2.3) was resolved to 4.2.3, which depends on
|
98
|
+
|
99
|
+
activerecord (= 4.2.3)
|
100
|
+
|
101
|
+
```
|