【问题标题】:Trouble with $.getJSON and Google Maps API V3$.getJSON 和 Google Maps API V3 的问题
【发布时间】:2013-09-06 16:50:48
【问题描述】:

谁能解释我在这里做错了什么?我正在使用 jQuery $.getJSON 和谷歌地图,我都是新手。最初我使用的是标准 JavaScript,但决定使用 jQuery,因为 XMLHttpRequest 在 Chrome 或 jsfiddle 中不起作用,据我了解,我不必担心使用 .$getJSON 的这些问题,但是我现在必须重建我的代码在 jQuery 中正常工作。

        <!DOCTYPE html>
    <html> 
    <head> 
      <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> 
      <title>Google Maps Multiple Markers - jQuery JSON</title> 
      <script src="http://maps.google.com/maps/api/js?sensor=false" 
              type="text/javascript"></script>
      <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
      <script type="text/javascript" src="js/jquery.ui.map.js"></script>
    </head> 
    <body>
      <div id="map_canvas" style="width: 800px; height: 600px;"></div>

      <script type="text/javascript">
          $(function(){
    $('#map_canvas').gmap().bind('init', function(){
        $.getJSON('http://www.artectodesignstudios.com/RSSData.txt', function(data){
            $.each(data.title, function(i, marker){
                $('#map_canvas').gmap('addMarker',{
                    'position': new google.maps.LatLng(marker[i]["geo:lat"], marker[i]["geo:long"]),
                    'bounds':true
            }).click(function(){
                $('#map_canvas').gmap('openInfoWindow', {'content': marker.content}, this);
            });

           });
        });
    });
});
    <script>
        </body>
        </html>

【问题讨论】:

  • 请先修复语法错误(提示:第一行缺少“v”。那么url: ... 部分就没有意义了)

标签: jquery google-maps getjson jsfiddle


【解决方案1】:

您需要处理您的 url 字符串,因为它不起作用。我建议您从 (http://jquery-ui-map.googlecode.com/svn/trunk/demos/json/demo.json) 之类的简单内容开始,然后围绕 JSON 格式使用来自所需 http://www.artectodesignstudios.com/RSSData.txt 请求的相同响应来编辑您的测试数据。 希望能帮助到你。 :)

【讨论】:

    猜你喜欢
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-14
    • 1970-01-01
    • 2011-07-29
    • 1970-01-01
    • 2010-11-28
    相关资源
    最近更新 更多