如何使用FlaskPython将GeoJson数据发布到网页-未捕获的SyntaxError:意外令牌'&'“

问题描述

我的flask网络应用程序在将geoJson文件发布到前端时遇到了麻烦。

烧瓶代码

geojson_sample = {
  "type": "FeatureCollection","features": [
    {
      "type": "Feature","properties": {
        "icon": "http://maps.google.com/mapfiles/ms/micons/pink-pushpin.png","marker-color": "#7e7e7e","marker-size": "medium","marker-symbol": "","Name": "Home"
      },"geometry": {
        "type": "Point","coordinates": [
          150.84022521972656,-34.44315867450577
        ]
      }
    },{
      "type": "Feature","Name": "Airport"
      },"coordinates": [
          150.79010009765625,-34.55888020163025
        ]
      }
    },"properties": {
        "icon": "/static/img/marker/map-mark.png","Name": "Work"
      },"coordinates": [
          150.78632354736328,-34.33606548328852
        ]
      }
    }
  ]
} 


@app.route("/test",methods=['GET','POST'])
def test():
    return render_template("test.html",posts=geojson_sample)

test.html页面显示错误“未捕获的SyntaxError:意外的令牌'&'”

            var geoJson = {'type': 'FeatureCollection','features': [{'type': 'Feature','properties': {'icon': 'http://maps.google.com/mapfiles/ms/micons/pink-pushpin.png','marker-color': '#7e7e7e','marker-size': 'medium','marker-symbol': '','Name': 'Home'},'geometry': {'type': 'Point','coordinates': [150.84022521972656,-34.44315867450577]}},{'type': 'Feature','Name': 'Airport'},'coordinates': [150.79010009765625,-34.55888020163025]}},'properties': {'icon': '/static/img/marker/map-mark.png','Name': 'Work'},'coordinates': [150.78632354736328,-34.33606548328852]}}]}
            // var geoJson = {
            //   type: "FeatureCollection",//   features: [
            //     {
            //       type: "Feature",//       properties: {
            //         icon:
            //           "http://maps.google.com/mapfiles/ms/micons/pink-pushpin.png",//         "marker-color": "#7e7e7e",//         "marker-size": "medium",//         "marker-symbol": "",//         Name: "Home",//       },//       geometry: {
            //         type: "Point",//         coordinates: [150.84022521972656,-34.44315867450577],//     },//     {
            //       type: "Feature",//         Name: "Airport",//         coordinates: [150.79010009765625,-34.55888020163025],//       properties: {
            //         icon: "/static/img/marker/map-mark.png",//         Name: "Work",//         coordinates: [150.78632354736328,-34.33606548328852],//   ],// };



            function initMap() {
                var map = new google.maps.Map(document.getElementById("map"),{
                    zoom: 8,center: {
                    lat: -34,lng: 150,},mapTypeId: google.maps.MapTypeId.TERRAIN,});

                    var markerCollection = map.data.addGeoJson(geoJson);

注意:它与带注释的var geoJson一起使用(如果我取消注释的话),但是当我从Flask发布它时却不能。任何想法表示赞赏:)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)