我正在使用Esri GIS从地址加载中心位置。但是我使用Google的geocoder来获取经度和纬度。我陷入了这个错误:
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);
}
});
});
答案 0 :(得分:0)
问题出在新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
应该向您展示如何使用该方法!