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

Javascript 使用传单esri插件对数据库中的地址名称进行地理编码,javascript,leaflet,geocoding,esri,Javascript,Leaflet,Geocoding,Esri,我试图建立一个地图应用程序,使用数据库中的地址名称和显示传单地图标记。我遇到过esri插件的传单,但不知道如何使用代码。有谁能教我如何从地理编码函数中提取结果(经度和纬度)并绘制标记?谢谢 地理编码功能: L.esri.Geocoding.geocode(<Object> options) 以下是使用ES6的示例: import L from "leaflet"; // import library as ELG import * as ELG from "esri-leaflet

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

地理编码功能:

L.esri.Geocoding.geocode(<Object> options)

以下是使用ES6的示例:

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();
});

谢谢kboul,但地理编码方法是什么?是不是L.esri.Geocoding.geocode()?geocode方法初始化一个新的地理编码任务,类似于
L.esri.Geocoding.geocode(选项)
,但采用ES6方式。当您使用
import
导入文件时,您可以创建一个文件,然后可以像使用vanilla js一样访问所有可用的方法。关于如何使用ES6导入添加外部库,也请检查此项。@NigelNg如果有帮助,请接受答案,以便其他用户在遇到相同问题时可以回答您的问题。谢谢提醒,这里是堆栈溢出新手。
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();
});