javascript - 如何确定哪个国家/州/地区/城市/地区位于传单多边形内 |长方形 |圆圈等

标签 javascript maps leaflet openstreetmap

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

最佳答案

我认为您正在寻找反向地理编码。 Leaflet不提供地理编码服务,但你可以找到类似的例子here.

Google 地理编码服务以 JSON 格式提供结果,但您可能需要为额外的配额付费。

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

更新了 Stack Snippet:

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>

关于javascript - 如何确定哪个国家/州/地区/城市/地区位于传单多边形内 |长方形 |圆圈等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39142259/

相关文章:

java - 如何创建 GPS 折线列表?

iphone - 是否有可能获得较长的注释?

javascript - 如何将 LeafletJS polylineDecorator 插件与 GeoJSON featureCollection 一起使用?

javascript - Leaflet - 设置工具提示样式

javascript - 传单标记

javascript - 传单 + Backbone.js : how to update the view on model collection update?

javascript - Twitter Bootstrap 工具提示无法使用 css 中的前缀

javascript - 将 Json 拖放到 Chrome 中

javascript - 套接字 io : how to pass paramter to disconnet socket event?

javascript - JavaScript 中的 Onclick 属性操作?