0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Laravel 地理座標を文字と数字の文字列にエンコードするジオハッシュアルゴリズム

Last updated at Posted at 2021-01-18

saikiran/geohashライブラリをインストール

saikiran/geohash

composer require saikiran/geohash

地理的な位置を文字と数字の短い文字列にエンコードします。

use Sk\Geohash\Geohash;
$g = new Geohash();

public function run(Faker $faker)
{  
 // 緯度,経度,文字数
'geohash' => $g->encode($faker->latitude(), $faker->longitude(), 12),
}

文字と数字の文字列を緯度と経度にデコードします。

use Sk\Geohash\Geohash;
$g = new Geohash();

public function run(Faker $faker)
{  
'geohash' => $g-> decode('エンコードされた文字列', 12),
}
  • テーブルに緯度・経度を文字列かしたレコードを保持しておけば色々使い回しが出来そう!
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?