google API有一个简单的查询
响应包含边界,位置和完整地址(例如 - 俄罗斯)
但我现在需要 - 俄罗斯 - >欧洲,美国 - >北美,埃及 - >非洲。
怎么做?!
答案 0 :(得分:11)
使用Google API进行地理编码。
"address_components"
中的一个条目应该看起来像[ "country", "political" ]
,例如:
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
使用其"short_name"
值并根据以下内容将其转换为非洲大陆:
{
"AD": "Europe",
"AE": "Asia",
"AF": "Asia",
"AG": "North America",
"AI": "North America",
"AL": "Europe",
"AM": "Asia",
"AN": "North America",
"AO": "Africa",
"AQ": "Antarctica",
"AR": "South America",
"AS": "Australia",
"AT": "Europe",
"AU": "Australia",
"AW": "North America",
"AZ": "Asia",
"BA": "Europe",
"BB": "North America",
"BD": "Asia",
"BE": "Europe",
"BF": "Africa",
"BG": "Europe",
"BH": "Asia",
"BI": "Africa",
"BJ": "Africa",
"BM": "North America",
"BN": "Asia",
"BO": "South America",
"BR": "South America",
"BS": "North America",
"BT": "Asia",
"BW": "Africa",
"BY": "Europe",
"BZ": "North America",
"CA": "North America",
"CC": "Asia",
"CD": "Africa",
"CF": "Africa",
"CG": "Africa",
"CH": "Europe",
"CI": "Africa",
"CK": "Australia",
"CL": "South America",
"CM": "Africa",
"CN": "Asia",
"CO": "South America",
"CR": "North America",
"CU": "North America",
"CV": "Africa",
"CX": "Asia",
"CY": "Asia",
"CZ": "Europe",
"DE": "Europe",
"DJ": "Africa",
"DK": "Europe",
"DM": "North America",
"DO": "North America",
"DZ": "Africa",
"EC": "South America",
"EE": "Europe",
"EG": "Africa",
"EH": "Africa",
"ER": "Africa",
"ES": "Europe",
"ET": "Africa",
"FI": "Europe",
"FJ": "Australia",
"FK": "South America",
"FM": "Australia",
"FO": "Europe",
"FR": "Europe",
"GA": "Africa",
"GB": "Europe",
"GD": "North America",
"GE": "Asia",
"GF": "South America",
"GG": "Europe",
"GH": "Africa",
"GI": "Europe",
"GL": "North America",
"GM": "Africa",
"GN": "Africa",
"GP": "North America",
"GQ": "Africa",
"GR": "Europe",
"GS": "Antarctica",
"GT": "North America",
"GU": "Australia",
"GW": "Africa",
"GY": "South America",
"HK": "Asia",
"HN": "North America",
"HR": "Europe",
"HT": "North America",
"HU": "Europe",
"ID": "Asia",
"IE": "Europe",
"IL": "Asia",
"IM": "Europe",
"IN": "Asia",
"IO": "Asia",
"IQ": "Asia",
"IR": "Asia",
"IS": "Europe",
"IT": "Europe",
"JE": "Europe",
"JM": "North America",
"JO": "Asia",
"JP": "Asia",
"KE": "Africa",
"KG": "Asia",
"KH": "Asia",
"KI": "Australia",
"KM": "Africa",
"KN": "North America",
"KP": "Asia",
"KR": "Asia",
"KW": "Asia",
"KY": "North America",
"KZ": "Asia",
"LA": "Asia",
"LB": "Asia",
"LC": "North America",
"LI": "Europe",
"LK": "Asia",
"LR": "Africa",
"LS": "Africa",
"LT": "Europe",
"LU": "Europe",
"LV": "Europe",
"LY": "Africa",
"MA": "Africa",
"MC": "Europe",
"MD": "Europe",
"ME": "Europe",
"MG": "Africa",
"MH": "Australia",
"MK": "Europe",
"ML": "Africa",
"MM": "Asia",
"MN": "Asia",
"MO": "Asia",
"MP": "Australia",
"MQ": "North America",
"MR": "Africa",
"MS": "North America",
"MT": "Europe",
"MU": "Africa",
"MV": "Asia",
"MW": "Africa",
"MX": "North America",
"MY": "Asia",
"MZ": "Africa",
"NA": "Africa",
"NC": "Australia",
"NE": "Africa",
"NF": "Australia",
"NG": "Africa",
"NI": "North America",
"NL": "Europe",
"NO": "Europe",
"NP": "Asia",
"NR": "Australia",
"NU": "Australia",
"NZ": "Australia",
"OM": "Asia",
"PA": "North America",
"PE": "South America",
"PF": "Australia",
"PG": "Australia",
"PH": "Asia",
"PK": "Asia",
"PL": "Europe",
"PM": "North America",
"PN": "Australia",
"PR": "North America",
"PS": "Asia",
"PT": "Europe",
"PW": "Australia",
"PY": "South America",
"QA": "Asia",
"RE": "Africa",
"RO": "Europe",
"RS": "Europe",
"RU": "Europe",
"RW": "Africa",
"SA": "Asia",
"SB": "Australia",
"SC": "Africa",
"SD": "Africa",
"SE": "Europe",
"SG": "Asia",
"SH": "Africa",
"SI": "Europe",
"SJ": "Europe",
"SK": "Europe",
"SL": "Africa",
"SM": "Europe",
"SN": "Africa",
"SO": "Africa",
"SR": "South America",
"ST": "Africa",
"SV": "North America",
"SY": "Asia",
"SZ": "Africa",
"TC": "North America",
"TD": "Africa",
"TF": "Antarctica",
"TG": "Africa",
"TH": "Asia",
"TJ": "Asia",
"TK": "Australia",
"TM": "Asia",
"TN": "Africa",
"TO": "Australia",
"TR": "Asia",
"TT": "North America",
"TV": "Australia",
"TW": "Asia",
"TZ": "Africa",
"UA": "Europe",
"UG": "Africa",
"US": "North America",
"UY": "South America",
"UZ": "Asia",
"VC": "North America",
"VE": "South America",
"VG": "North America",
"VI": "North America",
"VN": "Asia",
"VU": "Australia",
"WF": "Australia",
"WS": "Australia",
"YE": "Asia",
"YT": "Africa",
"ZA": "Africa",
"ZM": "Africa",
"ZW": "Africa"
}
(从回答GeoLocation API)。
答案 1 :(得分:2)
最新列表(请参阅https://gist.github.com/nobuti/3816985和https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2):
import org.apache.spark.sql.functions._
df.select(df.columns.map(x => col(x).as(x.toLowerCase)): _*).show(false)
答案 2 :(得分:1)
要获取大陆,请在输入坐标中使用多边形分析中的点(从查找地址开始),您可以从此FusionTable containing the continent data获取该大陆。
代码段(将大陆放入信息窗口)。
google.load('visualization', '1', {'packages':['corechart', 'table', 'geomap']});
// no spaces original
var tableid = '1O_WugYFKPBS4GTkPdN_hof6QnldoZlnwtxMjbMU'; // 297050;
var layer;
var circle;
var meters = 0.5;
var lat = 37.4;
var lng = -122.1;
var marker = null;
var geocoder = null;
var infowindow = null;
function findAddress(address) {
if (!address)
var address=document.getElementById("address").value;
if ((address != '') && geocoder) {
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
if (results && results[0] && results[0].geometry && results[0].geometry.viewport)
map.fitBounds(results[0].geometry.viewport);
if (document.getElementById('address').value != '')
{
map.setCenter(results[0].geometry.location);
infowindow = new google.maps.InfoWindow(
{ content: '<b>'+address+'</b>',
size: new google.maps.Size(150,50)
});
marker = new google.maps.Marker({
position: results[0].geometry.location,
map: map,
title:address
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent('<b>'+address+'</b><br>'+results[0].geometry.location);
infowindow.open(map,marker);
});
var event = new Object();
event.latLng = results[0].geometry.location;
changeCenter(event);
// layer.setQuery("SELECT geometry FROM "+tableid+" WHERE ST_INTERSECTS(geometry,CIRCLE(LATLNG"+results[0].geometry.location+",1))");
}
} else {
alert("No results found");
}
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
}
function initialize() {
geocoder = new google.maps.Geocoder();
map = new google.maps.Map(document.getElementById('map_canvas'), {
center: new google.maps.LatLng(lat, lng),
zoom: 10,
disableDefaultUI: true,
navigationControl: true,
navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
mapTypeId: google.maps.MapTypeId.ROADMAP
});
google.maps.event.addListener(map, 'click', function(event) {
changeCenter(event);
});
layer = new google.maps.FusionTablesLayer({
query: {
select: '\'geometry\'',
from: tableid,
where: 'ST_INTERSECTS(\'geometry\', CIRCLE(LATLNG(' + lat + ',' + lng + '),' + meters + '))'
}
});
layer.setMap(map);
circle = new google.maps.Circle({
center: new google.maps.LatLng(lat, lng),
radius: meters,
map: map,
fillOpacity: 0.2,
strokeOpacity: 0.5,
strokeWeight: 1
});
}
function changeRadius(new_meters) {
if (new_meters != "") {
meters = new_meters;
layer.setOptions({
query: {
select: '\'geometry\'',
from: tableid,
where: 'ST_INTERSECTS(\'geometry\', CIRCLE(LATLNG(' + lat + ',' + lng + '),' + meters + '))'
}
});
circle.setRadius(parseInt(meters));
}
}
function changeCenter(event) {
lat = event.latLng.lat();
lng = event.latLng.lng();
layer.setOptions({
query: {
select: '\'geometry\'',
from: tableid,
where: 'ST_INTERSECTS(\'geometry\', CIRCLE(LATLNG(' + lat + ',' + lng + '),' + meters + '))'
}
});
circle.setCenter(event.latLng);
// query table for name, address, delivery
//set the query using the parameter
var queryText ="SELECT \'CONTINENT\', \'geometry\' FROM "+tableid+" WHERE ST_INTERSECTS(\'geometry\', CIRCLE(LATLNG(" + lat + "," + lng + ")," + meters + "));";
document.getElementById('FTQuery').innerHTML = queryText;
queryText = encodeURIComponent(queryText);
document.getElementById('encFTQuery').innerHTML = queryText;
var query = new google.visualization.Query('http://www.google.com/fusiontables/gvizdata?tq=' + queryText);
//set the callback function
query.send(openInfoWindowOnMarker);
}
function openInfoWindowOnMarker(response) {
if (!response) {
alert('no response');
return;
}
if (response.isError()) {
alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
return;
}
FTresponse = response;
//for more information on the response object, see the documentation
//http://code.google.com/apis/visualization/documentation/reference.html#QueryResponse
numRows = response.getDataTable().getNumberOfRows();
numCols = response.getDataTable().getNumberOfColumns();
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent('<div style="width:200px; height:20px;"><b>Continent: '+response.getDataTable().getValue(0,0)+'</b><br></div>');
infowindow.open(map,marker);
});
google.maps.event.trigger(marker, 'click');
}
google.maps.event.addDomListener(window, 'load', initialize);
html, body, #map_canvas {
height: 500px;
width: 500px;
margin: 0px;
padding: 0px
}
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<input type="text" id="address" name="address" value="France"></input>
<input type="button" id="geocodeAddress" name="geocodeAddress" value="Geocode" onclick="findAddress();"></input>
<br />
<div id="map_canvas"></div>
<div id="FTQuery"></div>
<div id="encFTQuery"></div>
答案 3 :(得分:1)
使用OpenCage Geocoder API服务,它拥有大陆的一个值。
https://geocoder.opencagedata.com/api
_type的可能值包括(但不限于):建筑物,道路,村庄,社区,城市,县,邮政编码,州州,州,地区,岛屿,国家,大陆,虚构,未知
答案 4 :(得分:0)
您可以使用http://country.io/continent.json将国家/地区ISO2代码映射到大陆ISO2代码。
使用此数据集https://github.com/datasets/continent-codes/blob/master/data/continent-codes.csv
将大陆ISO2代码转换为其代码国家ISO2代码到大陆ISO2代码{"BD": "AS", "BE": "EU", "BF": "AF"...}