XML Parsing Error: not well-formed, error trying to load GeoJSON

XML Parsing Error: not well-formed, error trying to load GeoJSON

更新:我使用 QGIS 打开了我的 GeoJSON 文件所在的 shapefile。我将图层保存为 this GeoJSON file, making sure to select the projection WGS84/EPSG:4326 when saving. But I still get the same error described below when I attempt to place the GeoJSON on a Google Maps layer. The original shapefile is here.

我正在尝试使用 Google 地图 API 将 this GeoJSON 添加到地图中。

我的代码。

<html>
  <body>
    <div id="map"></div>
    <script type="text/javascript">
        function initMap(){
            var map = new google.maps.Map(
                document.getElementById("map"),
                {
                    zoom: 9,
                    center: {lat: 26.6949358, lng: -80.3487426}
                }
            );
            map.data.loadGeoJson("path/to/city-boundaries.geojson")
        }
    </script>
    <script async defer src="https://maps.googleapis.com/maps/api/js?key=MY_GOOGLE_MAPS_API_KEY&callback=initMap">
    </script>
  </body>
</html>

但是当我在 Firefox 中打开 HTML 文件时,我在开发者控制台中看到以下错误。

XML Parsing Error: not well-formed
Location: file:///path/to/city-boundaries.geojson

如何修复此错误?

loadGeoJson 在幕后使用 XHR,它不适用于本地文件。这些文件需要由网络服务器提供。

来自the documentation

loadGeoJson(url[, options, callback])
Parameters:
url: string
options: Data.GeoJsonOptions optional
callback: function(Array) optional
Return Value: None
Loads GeoJSON from a URL, and adds the features to the collection.

NOTE: The GeoJSON is fetched using XHR, and may not work cross-domain. If you have issues, we recommend you fetch the GeoJSON using your choice of AJAX library, and then call addGeoJson().