如何确定哪个国家/州/地区/城市/地区位于传单多边形/矩形/圆形等

How to determine which country/ state/ region/ city/ locality lies inside a leaflet polygon | rectangle | circle etc

本文关键字:地区 多边形 于传单 矩形 城市 国家 何确定      更新时间:2023-09-26

如何确定哪个国家、州、地区、城市或地区位于用户创建的传单形状(多边形|矩形|圆形等)内?

我想你正在寻找反向编码。传单不提供编码服务,但你可以在这里找到类似的例子。

Google Geocoding服务提供JSON格式的结果,但您可能需要支付额外的配额。

示例链接:http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224

-73.961452

用堆栈代码段更新:

window.cb = function cb(json) {
  document.getElementById('result').innerHTML = 'Country:' + json.address.country + '|' + 'State:' + json.address.state + '|' + 'County:' + json.address.county + '|' + 'City:' + json.address.city;
}
window.getLocation = function getLocation() {
  var s = document.createElement('script');
  s.src = 'http://nominatim.openstreetmap.org/reverse?json_callback=cb&format=json&lat=40.714224&lon=-73.961452&zoom=27&addressdetails=1';
  document.getElementsByTagName('head')[0].appendChild(s);
};
.myText {font-weight:bold;font-size:1.0em;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button onclick="getLocation();" name="search" class='myText'>Get Location!</button>
<p id="result" class='myText'></p>