Google maps API. Get continent where the country i

2020-06-04 09:36发布

问题:

There is a simple query to google API

https://maps.googleapis.com/maps/api/geocode/json?address=&components=country:Russia&language=ru&key=MY_API_KEY

Response contain the bounds, location and full address (for example - Russia)

But i need to now that - Russia -> Europe, USA -> north America, Egypt -> Africa.

How to do it?!

回答1:

Geocode with Google API.

One of entries in "address_components" should look like that [ "country", "political" ], e.g.:

{
  "long_name" : "United States",
  "short_name" : "US",
  "types" : [ "country", "political" ]
},

use its "short_name" value and convert it to the continent according to:

{
  "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"
}

(from answer to GeoLocation API).



回答2:

Up to date list (see https://gist.github.com/nobuti/3816985 and https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) :

var continent = { //see https://gist.github.com/nobuti/3816985
"AF":"Asia", // "Islamic Republic of Afghanistan") 
"AX":"Europe", // "Åland Islands") 
"AL":"Europe", // "Republic of Albania") 
"DZ":"Africa", // "People's Democratic Republic of Algeria") 
"AS":"Oceania", // "American Samoa") 
"AD":"Europe", // "Principality of Andorra") 
"AO":"Africa", // "Republic of Angola") 
"AI":"North America", // "Anguilla") 
"AQ":"Antarctica", // "Antarctica (the territory South of 60 deg S)") 
"AG":"North America", // "Antigua and Barbuda") 
"AR":"South America", // "Argentine Republic") 
"AM":"Asia", // "Republic of Armenia") 
"AW":"North America", // "Aruba") 
"AU":"Oceania", // "Commonwealth of Australia") 
"AT":"Europe", // "Republic of Austria") 
"AZ":"Asia", // "Republic of Azerbaijan") 
"BS":"North America", // "Commonwealth of the Bahamas") 
"BH":"Asia", // "Kingdom of Bahrain") 
"BD":"Asia", // "People's Republic of Bangladesh") 
"BB":"North America", // "Barbados") 
"BY":"Europe", // "Republic of Belarus") 
"BE":"Europe", // "Kingdom of Belgium") 
"BZ":"North America", // "Belize") 
"BJ":"Africa", // "Republic of Benin") 
"BM":"North America", // "Bermuda") 
"BT":"Asia", // "Kingdom of Bhutan") 
"BO":"South America", // "Plurinational State of Bolivia") 
"BQ":"North America", // '535' 
"BA":"Europe", // "Bosnia and Herzegovina") 
"BW":"Africa", // "Republic of Botswana") 
"BV":"Antarctica", // "Bouvet Island (Bouvetoya)") 
"BR":"South America", // "Federative Republic of Brazil") 
"IO":"Asia", // "British Indian Ocean Territory (Chagos Archipelago)") 
"VG":"North America", // "British Virgin Islands") 
"BN":"Asia", // "Brunei Darussalam") 
"BG":"Europe", // "Republic of Bulgaria") 
"BF":"Africa", // "Burkina Faso") 
"BI":"Africa", // "Republic of Burundi") 
"KH":"Asia", // "Kingdom of Cambodia") 
"CM":"Africa", // "Republic of Cameroon") 
"CA":"North America", // "Canada") 
"CV":"Africa", // "Republic of Cape Verde") 
"KY":"North America", // "Cayman Islands") 
"CF":"Africa", // "Central African Republic") 
"TD":"Africa", // "Republic of Chad") 
"CL":"South America", // "Republic of Chile") 
"CN":"Asia", // "People's Republic of China") 
"CX":"Asia", // "Christmas Island") 
"CC":"Asia", // "Cocos (Keeling) Islands") 
"CO":"South America", // "Republic of Colombia") 
"KM":"Africa", // "Union of the Comoros") 
"CD":"Africa", // "Democratic Republic of the Congo") 
"CG":"Africa", // "Republic of the Congo") 
"CK":"Oceania", // "Cook Islands") 
"CR":"North America", // "Republic of Costa Rica") 
"CI":"Africa", // "Republic of Cote d'Ivoire") 
"HR":"Europe", // "Republic of Croatia") 
"CU":"North America", // "Republic of Cuba") 
"CW":"North America", // "Curaçao") 
"CY":"Asia", // "Republic of Cyprus") 
"CZ":"Europe", // "Czech Republic") 
"DK":"Europe", // "Kingdom of Denmark") 
"DJ":"Africa", // "Republic of Djibouti") 
"DM":"North America", // "Commonwealth of Dominica") 
"DO":"North America", // "Dominican Republic") 
"EC":"South America", // "Republic of Ecuador") 
"EG":"Africa", // "Arab Republic of Egypt") 
"SV":"North America", // "Republic of El Salvador") 
"GQ":"Africa", // "Republic of Equatorial Guinea") 
"ER":"Africa", // "State of Eritrea") 
"EE":"Europe", // "Republic of Estonia") 
"ET":"Africa", // "Federal Democratic Republic of Ethiopia") 
"FO":"Europe", // "Faroe Islands") 
"FK":"South America", // "Falkland Islands (Malvinas)") 
"FJ":"Oceania", // "Republic of Fiji") 
"FI":"Europe", // "Republic of Finland") 
"FR":"Europe", // "French Republic") 
"GF":"South America", // "French Guiana") 
"PF":"Oceania", // "French Polynesia") 
"TF":"Antarctica", // "French Southern Territories") 
"GA":"Africa", // "Gabonese Republic") 
"GM":"Africa", // "Republic of the Gambia") 
"GE":"Asia", // "Georgia") 
"DE":"Europe", // "Federal Republic of Germany") 
"GH":"Africa", // "Republic of Ghana") 
"GI":"Europe", // "Gibraltar") 
"GR":"Europe", // "Hellenic Republic Greece") 
"GL":"North America", // "Greenland") 
"GD":"North America", // "Grenada") 
"GP":"North America", // "Guadeloupe") 
"GU":"Oceania", // "Guam") 
"GT":"North America", // "Republic of Guatemala") 
"GG":"Europe", // "Bailiwick of Guernsey") 
"GN":"Africa", // "Republic of Guinea") 
"GW":"Africa", // "Republic of Guinea-Bissau") 
"GY":"South America", // "Co-operative Republic of Guyana") 
"HT":"North America", // "Republic of Haiti") 
"HM":"Antarctica", // "Heard Island and McDonald Islands") 
"VA":"Europe", // "Holy See (Vatican City State)") 
"HN":"North America", // "Republic of Honduras") 
"HK":"Asia", // "Hong Kong Special Administrative Region of China") 
"HU":"Europe", // "Hungary") 
"IS":"Europe", // "Republic of Iceland") 
"IN":"Asia", // "Republic of India") 
"ID":"Asia", // "Republic of Indonesia") 
"IR":"Asia", // "Islamic Republic of Iran") 
"IQ":"Asia", // "Republic of Iraq") 
"IE":"Europe", // "Ireland") 
"IM":"Europe", // "Isle of Man") 
"IL":"Asia", // "State of Israel") 
"IT":"Europe", // "Italian Republic") 
"JM":"North America", // "Jamaica") 
"JP":"Asia", // "Japan") 
"JE":"Europe", // "Bailiwick of Jersey") 
"JO":"Asia", // "Hashemite Kingdom of Jordan") 
"KZ":"Asia", // "Republic of Kazakhstan") 
"KE":"Africa", // "Republic of Kenya") 
"KI":"Oceania", // "Republic of Kiribati") 
"KP":"Asia", // "Democratic People's Republic of Korea") 
"KR":"Asia", // "Republic of Korea") 
"KW":"Asia", // "State of Kuwait") 
"KG":"Asia", // "Kyrgyz Republic") 
"LA":"Asia", // "Lao People's Democratic Republic") 
"LV":"Europe", // "Republic of Latvia") 
"LB":"Asia", // "Lebanese Republic") 
"LS":"Africa", // "Kingdom of Lesotho") 
"LR":"Africa", // "Republic of Liberia") 
"LY":"Africa", // "Libya") 
"LI":"Europe", // "Principality of Liechtenstein") 
"LT":"Europe", // "Republic of Lithuania") 
"LU":"Europe", // "Grand Duchy of Luxembourg") 
"MO":"Asia", // "Macao Special Administrative Region of China") 
"MK":"Europe", // "Republic of Macedonia") 
"MG":"Africa", // "Republic of Madagascar") 
"MW":"Africa", // "Republic of Malawi") 
"MY":"Asia", // "Malaysia") 
"MV":"Asia", // "Republic of Maldives") 
"ML":"Africa", // "Republic of Mali") 
"MT":"Europe", // "Republic of Malta") 
"MH":"Oceania", // "Republic of the Marshall Islands") 
"MQ":"North America", // "Martinique") 
"MR":"Africa", // "Islamic Republic of Mauritania") 
"MU":"Africa", // "Republic of Mauritius") 
"YT":"Africa", // "Mayotte") 
"MX":"North America", // "United Mexican States") 
"FM":"Oceania", // "Federated States of Micronesia") 
"MD":"Europe", // "Republic of Moldova") 
"MC":"Europe", // "Principality of Monaco") 
"MN":"Asia", // "Mongolia") 
"ME":"Europe", // "Montenegro") 
"MS":"North America", // "Montserrat") 
"MA":"Africa", // "Kingdom of Morocco") 
"MZ":"Africa", // "Republic of Mozambique") 
"MM":"Asia", // "Republic of the Union of Myanmar") 
"NA":"Africa", // "Republic of Namibia") 
"NR":"Oceania", // "Republic of Nauru") 
"NP":"Asia", // "Federal Democratic Republic of Nepal") 
"NL":"Europe", // "Kingdom of the Netherlands") 
"NC":"Oceania", // "New Caledonia") 
"NZ":"Oceania", // "New Zealand") 
"NI":"North America", // "Republic of Nicaragua") 
"NE":"Africa", // "Republic of Niger") 
"NG":"Africa", // "Federal Republic of Nigeria") 
"NU":"Oceania", // "Niue") 
"NF":"Oceania", // "Norfolk Island") 
"MP":"Oceania", // "Commonwealth of the Northern Mariana Islands") 
"NO":"Europe", // "Kingdom of Norway") 
"OM":"Asia", // "Sultanate of Oman") 
"PK":"Asia", // "Islamic Republic of Pakistan") 
"PW":"Oceania", // "Republic of Palau") 
"PS":"Asia", // "Occupied Palestinian Territory") 
"PA":"North America", // "Republic of Panama") 
"PG":"Oceania", // "Independent State of Papua New Guinea") 
"PY":"South America", // "Republic of Paraguay") 
"PE":"South America", // "Republic of Peru") 
"PH":"Asia", // "Republic of the Philippines") 
"PN":"Oceania", // "Pitcairn Islands") 
"PL":"Europe", // "Republic of Poland") 
"PT":"Europe", // "Portuguese Republic") 
"PR":"North America", // "Commonwealth of Puerto Rico") 
"QA":"Asia", // "State of Qatar") 
"RE":"Africa", // "Réunion") 
"RO":"Europe", // "Romania") 
"RU":"Europe", // "Russian Federation") 
"RW":"Africa", // "Republic of Rwanda") 
"BL":"North America", // "Saint Barthélemy") 
"SH":"Africa", // '654' 
"KN":"North America", // "Federation of Saint Kitts and Nevis") 
"LC":"North America", // "Saint Lucia") 
"MF":"North America", // "Saint Martin (French part)") 
"PM":"North America", // "Saint Pierre and Miquelon") 
"VC":"North America", // "Saint Vincent and the Grenadines") 
"WS":"Oceania", // "Independent State of Samoa") 
"SM":"Europe", // "Republic of San Marino") 
"ST":"Africa", // "Democratic Republic of Sao Tome and Principe") 
"SA":"Asia", // "Kingdom of Saudi Arabia") 
"SN":"Africa", // "Republic of Senegal") 
"RS":"Europe", // "Republic of Serbia") 
"SC":"Africa", // "Republic of Seychelles") 
"SL":"Africa", // "Republic of Sierra Leone") 
"SG":"Asia", // "Republic of Singapore") 
"SX":"North America", // "Sint Maarten (Dutch part)") 
"SK":"Europe", // "Slovakia (Slovak Republic)") 
"SI":"Europe", // "Republic of Slovenia") 
"SB":"Oceania", // "Solomon Islands") 
"SO":"Africa", // "Somali Republic") 
"ZA":"Africa", // "Republic of South Africa") 
"GS":"Antarctica", // "South Georgia and the South Sandwich Islands") 
"SS":"Africa", // "Republic of South Sudan") 
"ES":"Europe", // "Kingdom of Spain") 
"LK":"Asia", // "Democratic Socialist Republic of Sri Lanka") 
"SD":"Africa", // "Republic of Sudan") 
"SR":"South America", // "Republic of Suriname") 
"SJ":"Europe", // "Svalbard & Jan Mayen Islands") 
"SZ":"Africa", // "Kingdom of Swaziland") 
"SE":"Europe", // "Kingdom of Sweden") 
"CH":"Europe", // "Swiss Confederation") 
"SY":"Asia", // "Syrian Arab Republic") 
"TW":"Asia", // "Taiwan 
"TJ":"Asia", // "Republic of Tajikistan") 
"TZ":"Africa", // "United Republic of Tanzania") 
"TH":"Asia", // "Kingdom of Thailand") 
"TL":"Asia", // "Democratic Republic of Timor-Leste") 
"TG":"Africa", // "Togolese Republic") 
"TK":"Oceania", // "Tokelau") 
"TO":"Oceania", // "Kingdom of Tonga") 
"TT":"North America", // "Republic of Trinidad and Tobago") 
"TN":"Africa", // "Tunisian Republic") 
"TR":"Asia", // "Republic of Turkey") 
"TM":"Asia", // "Turkmenistan") 
"TC":"North America", // "Turks and Caicos Islands") 
"TV":"Oceania", // "Tuvalu") 
"UG":"Africa", // "Republic of Uganda") 
"UA":"Europe", // "Ukraine") 
"AE":"Asia", // "United Arab Emirates") 
"GB":"Europe", // "United Kingdom of Great Britain & Northern Ireland") 
"US":"North America", // "United States of America") 
"UM":"Oceania", // "United States Minor Outlying Islands") 
"VI":"North America", // "United States Virgin Islands") 
"UY":"South America", // "Eastern Republic of Uruguay") 
"UZ":"Asia", // "Republic of Uzbekistan") 
"VU":"Oceania", // "Republic of Vanuatu") 
"VE":"South America", // "Bolivarian Republic of Venezuela") 
"VN":"Asia", // "Socialist Republic of Vietnam") 
"WF":"Oceania", // "Wallis and Futuna") 
"EH":"Africa", // "Western Sahara") 
"YE":"Asia", // "Yemen") 
"ZM":"Africa", // "Republic of Zambia") 
"ZW":"Africa" // "Republic of Zimbabwe"); 
}



回答3:

To get the continent, use point in polygon analysis with your input coordinates (from the address look up), you can get the continent from this FusionTable containing the continent data.

Code snippet (puts the continent in the infowindow).

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>



回答4:

Use the OpenCage Geocoder API service, it has continent has one of its values.

https://geocoder.opencagedata.com/api

Possible values of _type include (but are not limited to): building, road, village, neighbourhood, city, county, postcode, state_district, state, region, island, country, continent, ficticious, unknown



回答5:

You can use http://country.io/continent.json to map country ISO2 code to continent ISO2 code.

And convert continent ISO2 code to its with this dataset https://github.com/datasets/continent-codes/blob/master/data/continent-codes.csv

Example of country ISO2 code to continent ISO2 code {"BD": "AS", "BE": "EU", "BF": "AF"...}