LoginSignup
1
1

More than 5 years have passed since last update.

[C#]地名から緯度経度を取得する

Posted at

地名から緯度経度を取得する方法

地名を渡すと緯度経度を取得する方法@C# asp.netです。

今回用いるのはこちら → GoogleLocationService

開発環境

とりあえずの情報として
・VisualStudio 2015
・entiry framework 6.0

手順

1.VisualStudioで適当なソリューションを準備します。
2.パッケージマネージャーコンソールから対象のソリューションに以下を流します。

Install-Package GoogleMaps.LocationServices -Version 1.2.0.1

3.あとは適宜必要なusingを追加しながら用いていくだけ

以下参考コード

var locationService = new GoogleLocationService([YourGoogleAPIKey]);
var point = locationService.GetLatLongFromAddress([地名]);

pointには{緯度,経度}の形式で取得結果が格納されます。

注意点

・GoogleLocationServiceのInstanceを生成する際にGoogleAPIKeyを引数に渡さないと、時間当たりの使用回数に限度が生じます。
・条件は謎ですが、一部取得できない地名などが存在します。
 →「表参道」(「omotesandou」)で取得を試みた際になぜかnullが返ってきました…

地名から緯度経度を取得したい場合にはこんなんでできるよっていう

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