【问题标题】:Parse ESRI JSON coordinates from the candidate responseText从候选 responseText 解析 ESRI JSON 坐标
【发布时间】:2015-11-15 20:49:09
【问题描述】:

我正在使用 ESRI 对 SharePoint 2010 中的地址进行地理编码。我能够在 console.log 中获取地址的响应文本,但我无法弄清楚如何解析 x 和 y从候选人。有两个目标:1)解析候选[0] x 和 y,2)如果可能,在地图上映射其他可能的候选(显示它们),以便用户可以查看另一个点是否是他们真正的意思。

这是我的 json 输出:

{"spatialReference":{"wkid":4326,"latestWkid":4326},"candidates":[{"address":"Detroit, Michigan, United States","location":{"x":-83.04574875899965,"y":42.3314259010005},"score":100,"attributes":{},"extent":{"xmin":-83.188749999999999,"ymin":42.188426,"xmax":-82.902749999999997,"ymax":42.474426000000001}}]} 

这是我的 javascript:

var request;
                if (window.XMLHttpRequest) {
                    request = new XMLHttpRequest();
                } else {
                    request = new ActiveXObject("Microsoft.XMLHTTP");
                }
                console.log('url used:'+url);
                request.open('GET', url);
                request.onreadystatechange = function() {
                    if ((request.readyState===4) && (request.status===200)) {
                        console.log('response: '+request.responseText);
                        var data = JSON.parse(request.responseText);

                        for (var key in data) {
                            console.log(data[key].value);
                        }

                        //var lat = data.spatialReference.candidates[0].address.x;
                        //console.log('lat:'+lat);
                        //var items = JSON.parse(request.responseText);
                        //var output = '<ul>';
                        //for (var key in items) {
                        //  output += '<li>' + items[key].name + '</li>';
                        //}
                        //output += '</ul>';
                        //document.getElementById('update').innerHTML = output;
                    }
                }
                request.send();

【问题讨论】:

    标签: json sharepoint esri


    【解决方案1】:

    您应该在每个 data.candidates 中查找位置对象,其中包含您需要的信息。

    for (var i=0; i<= data.candidates.length; i++) {
       cand = data.candidates[i];
       if (cand) { 
         console.log(cand.location);
         console.log("x- " + cand.location.x);
         console.log("y- " + cand.location.y);
       }
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-15
      • 2018-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-16
      • 1970-01-01
      相关资源
      最近更新 更多