【问题标题】:Jvectormap markers from json来自json的Jvectormap标记
【发布时间】:2013-08-18 08:15:34
【问题描述】:
$(function(){
$.getJSON('data.json', function(data){
new jvm.WorldMap({
map: 'world_mill_en',
container: $('#map'),
markers: [
  {latLng: [47.5, 19.0833], name: '1'},
  {latLng: [51.5170, -0.1050], name: '2'}
],
//markers : data.results,
});
});
});

代码有效,但从 JSON 加载时没有任何反应。我假设我的 JSON 格式不正确。如何更正我的 data.json?

{["latLng":[47.5,19.0833], "name": "1"},{latLng: [51.5170, -0.1050], name: "2"}]}

【问题讨论】:

    标签: jquery world-map


    【解决方案1】:

    所以这就是那些来这个问题寻找正确答案的人的答案-

    这应该是<script>标签里面的代码:

    $(function(){
        $.getJSON('data.json', function (data) {
          $('#world-map').vectorMap({
            map: 'world_merc',
            hoverOpacity: 0.7,
            hoverColor: false,
            backgroundColor: '#ddd',
            markerStyle: {
                initial: {  
                    stroke: null
                }
            },
            markers: data       // --- The data from the JSON file will be given here
            })
          }); 
        });
    

    JSON文件如下:

    [
        {
            "latLng": [-36.85, 174.78],
            "name": "Singapore",
            "style": {"fill": "green"}
        },
        {
            "latLng": [-36.85, 174.78],
            "name": "Brazilia",
            "style": {"fill": "green"}
        },
        {
            "latLng": [-36.85, 174.78],
            "name": "Rio De Janeiro",
            "style": {"fill": "green"}
        }
    ]
    

    (PS:JSON文件中的样式行是用于另一个函数的。)

    希望对您有所帮助,干杯!

    【讨论】:

      【解决方案2】:

      您的第二个 Array 对象元素周围缺少引号。

      {["latLng":[47.5,19.0833], "name": "1"},{latLng: [51.5170, -0.1050], name: "2"}]}
      

      应该是

      {["latLng":[47.5,19.0833],"name":"1"},{"latLng":[51.5170,-0.1050],"name":"2"}]}
      

      【讨论】:

        猜你喜欢
        • 2013-01-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-03-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多