首页 > 解决方案 > Angular 页面中的 Esri 地图单击不再加载到经纬度?Object.b.locationToAddress 处为 null 的“toJSON”

问题描述

当前,当您单击 esri 地图时出现错误。该功能曾经有效。它发生在 locatorTask.locationToAddress(event.mapPoint).then(function (response) {

控制台中的错误如下所示: 在此处输入图像描述

这里的代码:

  mapView.when(function () {
  mapView.popup.autoOpenEnabled = false;
  mapView.on("click", function (event) {
    searchWidget.clear();
    mapView.popup.clear();
    locatorTask
      .locationToAddress(event.mapPoint)
      .then(function (response) {
        // If an address is successfully found, show it in the popup's content
        mapView.popup.content = response.address;
        var address = response.address;
        showPopup(address, event.mapPoint);
      })
      .catch(function (error) {
        // If the promise fails and no result is found, show a generic message
        mapView.popup.content = "No address was found for this location";
        showPopup("No address found.", event.mapPoint);
      });

    mapView.popup.visible = true;
  });
})

感谢您的任何建议或帮助!

标签: angulartypescriptesri

解决方案


您是否更改了 JavaScript API 版本?参数在版本 4.12 中已更改。

https://developers.arcgis.com/javascript/latest/guide/4.12/index.html

“将 locatorTask.locationToAddress() 参数从 (location, distance, requestOptions) 更改为现在接受 (params, requestOptions)。params 对象有两个属性:location 和 locationType。”

可以在此处找到新文档: https ://developers.arcgis.com/javascript/latest/api-reference/esri-tasks-Locator.html#locationToAddress

您的代码应该是:

locatorTask
      .locationToAddress(location:{event.mapPoint})
      .then(function (response) {

推荐阅读