"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(user_agent="my-app")
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的Nominatim。您只需要在URL中设置变量,它就会返回该位置的城市/国家。请查看以下链接获取官方文档: Nominatim
我正在寻找类似的功能,之前看到在回复中分享了数据“http://download.geonames.org/export/dump/”(感谢分享,这是一个很棒的资源),并基于cities1000.txt数据实现了一个服务。
您可以在以下链接中查看其运行情况:
http://scatter-otl.rhcloud.com/location?lat=36&long=-78.9 (链接已失效)
只需更改您的位置的纬度和经度即可。
它部署在OpenShift(红帽平台)上。第一次调用可能需要一些时间,但通常性能是令人满意的。 请随意使用此服务…
此外,您可以在以下链接中找到该项目的源代码: https://github.com/turgos/Location。
我曾使用Geocoder,这是一个很好的Python库,支持多个提供者,包括Google、Geonames和OpenStreetMaps等,只是举了几个例子。我尝试使用GeoPy库,但它经常会超时。开发自己的GeoNames代码并不是最好的时间利用方式,你可能最终得到不稳定的代码。我的经验是,Geocoder非常简单易用,并且有足够好的文档。下面是一些示例代码,用于按纬度和经度查找城市,或通过城市名称查找纬度/经度。
import geocoder
g = geocoder.osm([53.5343609, -113.5065084], method='reverse')
print g.json['city'] # Prints Edmonton
g = geocoder.osm('Edmonton, Canada')
print g.json['lat'], g.json['lng'] # Prints 53.5343609, -113.5065084
<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: '/' });
}
});
}
}
Loc2country 是一个基于 Golang 的工具,用于返回给定位置坐标(lat/lon)的 ISO alpha-3 国家代码。它以微秒级响应。它使用 geohash 到国家的映射。
geohash 数据是使用 georaptor 生成的。
我们在此工具中使用了 6 级 geohash,即大小为 1.2km x 600m 的方框。