如何从GeoJson数组获取坐标

时间:2019-12-03 15:59:13

标签: json geojson

我正在尝试从以下JSON数据获取坐标。 第一次尝试返回(Nan,Nan)值 但不起作用,如何访问它并在Google地图中显示该点? 这是我的代码:

// Creating the JSON data
    var json = "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson";          

    // Creating a global infoWindow object that will be reused by all markers
    var infoWindow = new google.maps.InfoWindow();

    // Looping through the JSON data    

    for (var i = 0, length = json.length; i < length; i++) {

        var data = json[i],
            latLng = new google.maps.LatLng(data.features[0].geometry.geometry['coordinates'][0],data.features[0].geometry.geometry['coordinates'][1]);
            alert(latLng);

        // Creating a marker and putting it on the map
        var marker = new google.maps.Marker({
            position: latLng,
            map: map,
            title: data.title
        });

        // Creating a closure to retain the correct data, notice how I pass the current data in the loop into the closure (marker, data)
        (function(marker, data) {

            // Attaching a click event to the current marker
            google.maps.event.addListener(marker, "click", function(e) {
                infoWindow.setContent(data.description);
                infoWindow.open(map, marker);
            });


        })(marker, data);

    }

0 个答案:

没有答案
相关问题