Google Map不会在Django中呈现Json数据

时间:2016-12-27 01:11:10

标签: javascript python json django

我尝试在带有标记的Google地图上的数据库中显示特定坐标。现在我试图使用一个简单的标记。

背景:

我在static / maps / jason_data.json

中有一个本地json文件

我正在使用google api,我在这里使用他们的模板。

    <div id="map"></div>

    <script async defer
    src="https://maps.googleapis.com/maps/api/js?key=APIKEY&callback=initMap">
    </script>

      <head>
        <style>
           #map {
            height: 600px;
            width: 800px;
        margin: 0 auto;
      }



    </style>
  </head>
  <body>
    <div id="map"></div>
    <script>


 var map;
  function initMap() {
    map = new google.maps.Map(document.getElementById('map'), {
      zoom: 14,
      center: new google.maps.LatLng(a,b),
      mapTypeId: 'roadmap'
    });

        results = map.data.loadGeoJson('/maps/json_data.json');


      window.eqfeed_callback = function(results) {
        for (var i = 0; i < results.features.length; i++) {
          var coords = results[i].features[0].geometry.coordinates;
          var latLng = new google.maps.LatLng(coords[1],coords[0]);
          var marker = new google.maps.Marker({
            position: latLng,
            map: map
          });
        }
      }
    </script>
  </body>
</html>

 </div>

我得到的错误是

Error parsing /maps/json_file.json: SyntaxError: Unexpected token < in JSON at position 1

json文件的一个例子

{"id48": {"type": "FeatureCollection", "features": [{"geometry": {"type": "Point", "coordinates": ["a", "-b"]}, "type": "Point"}], "properties": {"prop1": "property", "id": 48}},...}

我试图通过python格式化json文件,类似于其他GEOJson选项。

我很抱歉我之前没有使用过javascript。

0 个答案:

没有答案