解析JSON并将标记添加到谷歌地图

时间:2013-07-31 17:06:57

标签: javascript jquery json google-maps

我正在尝试解析一些JSON数据,然后将其转换为谷歌地图标记,但问题是我仍然收到此错误:

JSON数据后出现意外的非空白字符

    function initialize() {
  var myLatlng = new google.maps.LatLng(-35.889050,-64.735108);
  var mapOptions = {
    zoom: 4,
    center: myLatlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }

  var map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
    var jsonArch = '{ "codigo" : "3127" , "nombre" : "name" , "zona" : "3127" , "geoX" : "-58.443597" , "geoY" : "-34.807164" },{ "codigo" : "3128" , "nombre" : "name" , "zona" : "3128" , "geoX" : "-58.488797" , "geoY" : "-34.576852" },{ "codigo" : "3124" , "nombre" : "name" , "zona" : "3124" , "geoX" : "00.000000" , "geoY" : "00.000000" }';

    var archiJASON = jQuery.parseJSON(jsonArch);
    /*jQuery.parseJSON(jsonArch, function(json1) {*/
        jQuery.each( archiJASON, function(key, data) {
            var latLng = new google.maps.LatLng(parseFloat(data.geoX), parseFloat(data.geoY)); 
            // Creating a marker and putting it on the map
            var marker = new google.maps.Marker({
                position: latLng,
                map: map,
                title: data.nombre
            });
            marker.setMap(map);
        });
    /*});*/

}

google.maps.event.addDomListener(window, 'load', initialize);

地图可见,但我无法加载标记......

这是JSON数据:

'{ "codigo" : "3127" , "nombre" : "name" , "zona" : "3127" , "geoX" : "-58.443597" , "geoY" : "-34.807164" },{ "codigo" : "3128" , "nombre" : "name" , "zona" : "3128" , "geoX" : "-58.488797" , "geoY" : "-34.576852" },{ "codigo" : "3124" , "nombre" : "name" , "zona" : "3124" , "geoX" : "00.000000" , "geoY" : "00.000000" }'

非常感谢,任何帮助都会受到赞赏,这对我很重要。

0 个答案:

没有答案