0
0

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.

Heart rails 位置情報取得 APIをlaravelで使う

Last updated at Posted at 2022-03-14

郵便番号から最寄り駅が現在地を取得できるサービス。
まずは、POST、GET通信をするためにヘッダに以下を読み込む

use Illuminate\Support\Facades\Http;

//郵便番号から住所を
//都道府県・最寄り駅を取得

$postal = 3790111;

$response = Http::get('http://geoapi.heartrails.com/api/json', [
    'method' => 'searchByPostal',
    'postal' => $postal
]);

$json = $response->json();
pr($json['response']['location'][0]['prefecture']);//都道府県名
pr($json['response']['location'][0]['city']);//町名

$response = Http::get('http://geoapi.heartrails.com/api/json', [
    'method' => 'getStations',
    'postal' => $postal
]);

$json = $response->json();

pr($json['response']['station'][0]['name']);//最寄り駅の名前
pr($json['response']['station'][0]['line']);//最寄り駅が何線か

pr($json['response']['station'][0]['y']);//最寄り駅の y 軸
pr($json['response']['station'][0]['x']);//最寄り駅の x 軸

以上

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?