【问题标题】:ESRI TypeError: this.spatialReference is undefinedESRI TypeError:this.spatialReference 未定义
【发布时间】:2019-05-05 13:58:43
【问题描述】:

我正在使用 Esri GIS 从地址加载中心位置。但我使用谷歌的地理编码器来获取经度和纬度。我被这个错误困住了:

TypeError: this.spatialReference is undefined

你对这个问题有什么想法吗? 这是我的代码:

require(["esri/map", "esri/geometry/Point", "esri/symbols/SimpleMarkerSymbol", "esri/symbols/PictureMarkerSymbol", "esri/graphic",  "esri/layers/GraphicsLayer", "dojo/domReady!" ],
                function(Map, Point, SimpleMarkerSymbol, PictureMarkerSymbol, Graphic, GraphicsLayer) {

             var point = new Point(0, 0, new esri.SpatialReference({ wkid: gisMap['wkid'] }));
             map = new Map(mapHolder, {center: point,zoom: gisMap['zoomlevel']});
             var geocoder = new google.maps.Geocoder();     
                geocoder.geocode({ 'address': keyword}, function(results, status) {
                    if (status == google.maps.GeocoderStatus.OK) {
                        var  latitude= results[0].geometry.location.lat();
                        var longitude = results[0].geometry.location.lng();
                        console.log(longitude+"|"+latitude);
                        if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
                            map.centerAt(new Point(longitude,latitude));
                            console.log(map);

                        } else {
                              console.log("No results found");
                        }
                    } else {
                      console.log("Something got wrong " + status);
                    }
                });
            });

【问题讨论】:

  • 哪一行代码抛出了这个错误?你的代码从不使用this,所以这是彩票
  • 不确定,因为我已经有一段时间没有使用它了,但是您不必在您的需求中添加“esri/SpatialReference”,然后像使用新的 SpatialReference 而不是新的 esri.SpatialReference 一样使用它?

标签: javascript arcgis esri


【解决方案1】:

问题在于您对新 esri.SpatialReference 的初始化。您实际上并没有提供任何信息 - wkid 是“众所周知的 ID”的缩写,实际上并没有向 API 传达任何信息。

由于您没有指定您使用的 JS API 的版本(3.x 和 4.x 完全不同),我无法发布正确的代码来向您展示应该如何完成,但是这些两个资源: https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-SpatialReference.html

https://developers.arcgis.com/javascript/3/jsapi/spatialreference-amd.html

应该告诉你应该如何使用该方法!

【讨论】:

    猜你喜欢
    • 2015-09-05
    • 2017-12-01
    • 2021-02-24
    • 2016-11-24
    • 2014-12-20
    • 2015-10-13
    • 2020-06-18
    • 2014-10-23
    • 2014-05-30
    相关资源
    最近更新 更多