たとえば、これらの座標セットがある場合
"latitude": 48.858844300000001,
"longitude": 2.2943506,
都市/国を調べるにはどうすればよいですか?
たとえば、これらの座標セットがある場合
"latitude": 48.858844300000001,
"longitude": 2.2943506,
都市/国を調べるにはどうすればよいですか?
別のオプション:
利点:
短所:
無料のGoogle Geocoding APIは、HTTP REST API を介してこのサービスを提供します。API の使用量とレートは制限されていますが、無制限のアクセスに対して料金を支払うことができます。
このリンクを試して、出力の例を確認してください (これは json です。出力は XML でも利用できます)。
https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true
あなたが必要geopy
pip install geopy
その後:
from geopy.geocoders import Nominatim
geolocator = Nominatim()
location = geolocator.reverse("48.8588443, 2.2943506")
print(location.address)
詳細情報を取得するには:
print (location.raw)
{'place_id': '24066644', 'osm_id': '2387784956', 'lat': '41.442115', 'lon': '-8.2939909', 'boundingbox': ['41.442015', '41.442215', '-8.2940909', '-8.2938909'], 'address': {'country': 'Portugal', 'suburb': 'Oliveira do Castelo', 'house_number': '99', 'city_district': 'Oliveira do Castelo', 'country_code': 'pt', 'city': 'Oliveira, São Paio e São Sebastião', 'state': 'Norte', 'state_district': 'Ave', 'pedestrian': 'Rua Doutor Avelino Germano', 'postcode': '4800-443', 'county': 'Guimarães'}, 'osm_type': 'node', 'display_name': '99, Rua Doutor Avelino Germano, Oliveira do Castelo, Oliveira, São Paio e São Sebastião, Guimarães, Braga, Ave, Norte, 4800-443, Portugal', 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright'}
オープン ソースの代替手段は、Open Street Map の Nomintim です。URL に変数を設定するだけで、その場所の都市/国が返されます。公式ドキュメントについては、次のリンクを確認してください。
私はこの質問が本当に古いことを知っていますが、私は同じ問題に取り組んでおり、reverse_geocoder
Ajay Thampi によって構築された非常に効率的で便利なパッケージを見つけました。コードはこちらから入手できます。これは、大量のポイントに対して非常に効率的な KD ツリーの並列実装に基づいています (100,000 ポイントを取得するのに数秒かかりました。
これは、@turgos によって既に強調表示されているこのデータベースに基づいています。
座標リストの国と都市をすばやく見つけることが目的の場合、これは優れたツールです。
Javascript でこれを行う方法のコード例を見つけるのに約 30 分を費やしました。あなたが投稿した質問に対する明確な答えがすぐに見つかりませんでした。だから... 私は自分のものを作りました。API を掘り下げたり、読み方がわからないコードを凝視したりすることなく、これを使用できることを願っています。他に何もなければ、私は自分のもののためにこの投稿を参照することができます.. 良い質問と議論のフォーラムに感謝します!
これは Google API を利用しています。
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=<YOURGOOGLEKEY>&sensor=false&v=3&libraries=geometry"></script>
.
//CHECK IF BROWSER HAS HTML5 GEO LOCATION
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
//GET USER CURRENT LOCATION
var locCurrent = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
//CHECK IF THE USERS GEOLOCATION IS IN AUSTRALIA
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'latLng': locCurrent }, function (results, status) {
var locItemCount = results.length;
var locCountryNameCount = locItemCount - 1;
var locCountryName = results[locCountryNameCount].formatted_address;
if (locCountryName == "Australia") {
//SET COOKIE FOR GIVING
jQuery.cookie('locCountry', locCountryName, { expires: 30, path: '/' });
}
});
}
}
それは、あなたが持っているテクノロジーの制限に大きく依存します。
1 つの方法は、関心のある国と都市の概要を含む空間データベースを用意することです。概要とは、国と都市が空間タイプのポリゴンとして格納されることを意味します。座標のセットを空間タイプのポイントに変換し、ポリゴンに対してクエリを実行して、ポイントが配置されている国/都市名を取得できます。
空間タイプをサポートするデータベースの一部を以下に示します: SQL Server 2008、MySQL、postGIS - postgreSQL およびOracleの拡張。
このために独自のデータベースを持つ代わりにサービスを使用したい場合は、Yahoo のGeoPlanetを使用できます。サービス アプローチについては、gis.stackexchange.comでこの回答を確認することをお勧めします。これは、問題を解決するためのサービスの可用性をカバーしています。
Loc2countryは、指定された位置座標 (緯度/経度) の ISO alpha-3 国コードを返す Golang ベースのツールです。マイクロ秒単位で応答します。国マップへのジオハッシュを使用します。
geohash データは georaptor を使用して生成されます。
このツールには、レベル 6 の geohash を使用します。つまり、サイズが 1.2km x 600m のボックスです。
以下の回答をご確認ください。わたしにはできる
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position){
initialize(position.coords.latitude,position.coords.longitude);
});
}
function initialize(lat,lng) {
//directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions);
//directionsService = new google.maps.DirectionsService();
var latlng = new google.maps.LatLng(lat, lng);
//alert(latlng);
getLocation(latlng);
}
function getLocation(latlng){
var geocoder = new google.maps.Geocoder();
geocoder.geocode({'latLng': latlng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[0]) {
var loc = getCountry(results);
alert("location is::"+loc);
}
}
});
}
function getCountry(results)
{
for (var i = 0; i < results[0].address_components.length; i++)
{
var shortname = results[0].address_components[i].short_name;
var longname = results[0].address_components[i].long_name;
var type = results[0].address_components[i].types;
if (type.indexOf("country") != -1)
{
if (!isNullOrWhitespace(shortname))
{
return shortname;
}
else
{
return longname;
}
}
}
}
function isNullOrWhitespace(text) {
if (text == null) {
return true;
}
return text.replace(/\s/gi, '').length < 1;
}
ライブラリの量を最小限に抑えます。
ウェブサイトで API を使用するためのキーを取得し、http リクエストで結果を取得します。
curl -i -H "key: YOUR_KEY" -X GET https://api.latlong.dev/lookup?lat=38.7447913&long=-9.1625173