我正在使用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);
}
});
});发布于 2018-12-11 16:51:41
问题出在您初始化新的esri.SpatialReference时。您实际上并没有提供任何信息-- wkid是‘知名ID’的缩写,并且实际上不会向API传递任何信息。
因为您没有指定您正在使用的JS的版本(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
应该会告诉你应该如何使用这个方法!
https://stackoverflow.com/questions/53607905
复制相似问题