首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用leaflet esri插件对数据库中的地址名称进行地理编码

使用leaflet esri插件对数据库中的地址名称进行地理编码
EN

Stack Overflow用户
提问于 2018-12-22 16:48:03
回答 1查看 892关注 0票数 0

我正在尝试建立一个地图应用程序,使用数据库中的地址名称和在传单地图中显示标记。我遇到了leaflet esri插件,但不确定如何使用代码。谁能教我如何从地理编码函数中提取结果(经度和纬度)并绘制标记?谢谢!

地理编码函数:

代码语言:javascript
复制
L.esri.Geocoding.geocode(<Object> options)

结果:

代码语言:javascript
复制
{results: [
    {
      latlng: L.LatLng,
      text: 'Formatted Address',
      score: 100, // certainty ranking of the match
      properties: {
        // additional info like specific address components (Country Code etc.)
      }
    }
  ]
}

http://esri.github.io/esri-leaflet/api-reference/tasks/geocode.html

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-12-24 03:14:59

下面是一个使用ES6的示例:

代码语言:javascript
复制
import L from "leaflet";
// import library as ELG
import * as ELG from "esri-leaflet-geocoder";

// here is an example address in the US - use the one from your DB
const address = "380 New York St, Redlands, California, 92373";

// call geocode method of the library, no need to call L.esri.Geocoding.geocode() as in vanilla js
ELG.geocode()
  // pass the address
  .text(address)
  .run((err, results, response) => {
    console.log(results.results[0].latlng);
    // retrieve latitude, longitude from related response
    const { lat, lng } = results.results[0].latlng;
    // build a marker using the retrieved address
    L.marker([lat, lng])
      .addTo(mymap)
      .bindPopup(address)
      .openPopup();
});

Demo

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53894242

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档