jQuery自动完成与谷歌地图地址查找

时间:2012-06-24 15:10:44

标签: javascript jquery jquery-plugins google-maps-api-3 jquery-autocomplete

如何在jsfiddle中重现this plugin?到目前为止的代码是here。 我的问题是 - 我可以看到使用firebug的每个请求的响应数据,但自动完成列表没有显示。谢谢你的时间。

直接从小提琴添加代码 - HTML:

<!-- required js libraries -->
<script type="text/javascript" src="jquery-1.7.1.min.js"></script> <!-- jQuery is directly loaded from fiddle, so in the live example I skipped this line -->
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="http://gmap3.net/js/gmap3-4.1-min.js"></script>
<script type="text/javascript" src="https://raw.github.com/jbdemonte/autocomplete/master/jquery-autocomplete.min.js"></script>

<!-- this is required to help autocomplete plugin -->
<link rel="stylesheet" type="text/css" href="https://raw.github.com/jbdemonte/autocomplete/master/jquery-autocomplete.css" />

<input type="text" id="address" size="60"/>
<div id="test" style="height:350px; width:600px"></div>​

这是javascript:

/*This one initializes the map*/
$("#test").gmap3();

/*This is the autocomplete code*/
$('#address').autocomplete({
  source: function() {
    $("#test").gmap3({
      action:'getAddress',
      address: $(this).val(),
      callback:function(results){
        if (!results) return;
        $('#address').autocomplete(
          'display', 
          results,
          false
        );
      }
    });
  },
  cb:{
    cast: function(item){
      return item.formatted_address;
    },
    select: function(item) {
      $("#test").gmap3(
        {action:'clear', name:'marker'},
        {action:'addMarker',
          latLng:item.geometry.location,
          map:{center:true}
        }
      );
    }
  }
});​

1 个答案:

答案 0 :(得分:2)

通过将输入包装在容器中并在该容器和地图之间添加一些边距,可以使您的版本工作。我不认为css是从github资源正确传递的,因为我还必须添加一些额外的z-index以使结果列表显示在地图顶部

工作演示:http://jsfiddle.net/VBFxp/3/

相关问题