Javascript 为什么不显示标记-传单和JSON响应格式?

Javascript 为什么不显示标记-传单和JSON响应格式?,javascript,json,leaflet,geojson,Javascript,Json,Leaflet,Geojson,我使用的是传单和来自API调用的json响应。数据显示在调试器中标记、属性和几何体的变量中,但它不会显示标记。我的JSON格式错了吗?这方面我是新手。。 数据响应如下所示:6的数组。经度是响应中的正字符串 0:{样本ID:“4531”,visitNum:“1083”,齿轮类型:“EZ铸造净4英尺 半径,0.75磅”,居住区:“511”,地震代码:,…} 我试过pointToLayer,Oneach功能。我想显示的标记弹出窗口,如果我让他们显示 我试图用JSON.stringify(数据)进行字符

我使用的是传单和来自API调用的json响应。数据显示在调试器中标记、属性和几何体的变量中,但它不会显示标记。我的JSON格式错了吗?这方面我是新手。。 数据响应如下所示:6的数组。经度是响应中的正字符串

0:{样本ID:“4531”,visitNum:“1083”,齿轮类型:“EZ铸造净4英尺 半径,0.75磅”,居住区:“511”,地震代码:,…}

我试过pointToLayer,Oneach功能。我想显示的标记弹出窗口,如果我让他们显示

我试图用JSON.stringify(数据)进行字符串化;我不确定我应该用什么格式

    var jsonstring;

    $.getJSON("http://localhost:29694/api/Sample?VisitNum=1083", function (data) {
        jsonstring = JSON.stringify(data);
        jsondata = JSON.parse(jsonstring);
        var outGeoJson = {}
        for (i = 0 ; i < data.length; i++) {
            var longdata = data[i]["longStart"] * -1;
            var latdata = data[i]["latStart"] * 1;
            var latlng = [];
            latlng = [longdata, latdata];
            outGeoJson['properties'] = data[i]
            outGeoJson['type'] = "Feature"
            outGeoJson['geometry'] = {
                "type": "Point", "coordinates":
                    [longdata, latdata]
            }
            console.log(outGeoJson);

            var properties = [];
            properties = outGeoJson.properties;

            L.geoJSON(outGeoJson, {                                        
                pointToLayer: function (feature, latlng) {
                   var pmarker =   L.circleMarker(latlng, {
                        radius: 5,
                        fillColor: "#ff7800",
                        color: "#000",
                        weight: 1,
                        opacity: 1,
                        fillOpacity: 0.8
                    });
                 return pmarker;
            }
            }).addTo(map);

        }

    function lngLatToLatLng(lngLat) {
            return [latlng[1], latlng[0]];
        }
    });
欢迎来到SO

您只是忘记了从函数中返回新创建的
pmarker
圆圈标记


顺便说一句,不需要仅仅为了在传单中显示而在运行时构建GeoJSON对象;可以直接构建传单层。请参见

我添加了返回标记,但仍然没有标记。当传递到pointToLayer函数时,看起来latlng被翻转了。我添加了示例中所示的函数,将它们转换为lat/lng,但这也不起作用。我认为这是我和我的数据。谢谢你到目前为止的帮助。我想是我和我的数据。这些点在海洋中,所以我需要进一步调查。所以我得到了分数,只是不是我认为应该得到的。
{properties: {…}, type: "Feature", geometry: {…}}
geometry:
coordinates: (2) [-132.12211, 32.12122]
type: "Point"
__proto__: Object
properties:
depthSample: ""
depthWater: ""
duration: ""
endTime: "3/18/2019 12:00:00 AM"
gearType: "backpack efishing"
habitatID: "512"
latEnd: ""
latStart: "32.12122"
lengthTrawl: ""
longEnd: ""
longStart: "132.12211"
netter: "6"
notes: ""
percentOpen: ""
sampleCode: "EFISHBP1-HONK-18Mar2019"
sampleID: "4544"
seineCode: ""
startTime: "3/18/2019 12:00:00 AM"
towDirection: ""
visitNum: "1083"
volts: ""
width: ""
__proto__: Object
type: "Feature"
__proto__: Object