【问题标题】:How to determine which country/ state/ region/ city/ locality lies inside a leaflet polygon | rectangle | circle etc如何确定哪个国家/州/地区/城市/地区位于传单多边形内 |矩形 |圆圈等
【发布时间】:2016-08-25 10:03:01
【问题描述】:

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

【问题讨论】:

    标签: javascript maps leaflet openstreetmap


    【解决方案1】:

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

    Google 地理编码服务以 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>

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-02
    • 1970-01-01
    • 1970-01-01
    • 2015-04-14
    • 1970-01-01
    • 1970-01-01
    • 2014-12-30
    • 1970-01-01
    相关资源
    最近更新 更多