ste*_*tef 4 jquery google-maps jquery-ui-map
我有以下代码工作正常,但我无法添加缩放级别.根据它应该使用的文档,'option', 'zoom', 7但这给出了一个错误:"$("#map_canvas").gmap("option", "zoom", 7).bind is not a function"
工作代码,无法缩放,编辑.缩放始终为1.
$("#map_trigger").click(function(){
var prop_id = $("#map_canvas").attr("rel");
$('#map_canvas').gmap({'zoom':6}).bind('init', function(evt, map) {
$.getJSON( basepath+'properties/get_gps_coords/'+prop_id, function(data) {
$.each( data.markers, function(i, m) {
lat = m.latitude;
longitude = m.longitude;
$('#map_canvas').gmap(
'addMarker', { 'position': new google.maps.LatLng(lat, m.longitude), 'bounds':true }
);
});
});
});
});
Run Code Online (Sandbox Code Playgroud)
如何为此代码段添加缩放级别?
这段代码适合我:
<!doctype html>
<html>
<head>
<meta http-equiv="content-language" content="es">
<meta charset="utf-8">
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="js/jquery-1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="../ui/jquery.ui.map.js"></script>
</head>
<body>
<div style="height: 500px; width:500px;" id="map_canvas"></div>
<button id="btnChangeZoom">change zoom</button>
<script type="text/javascript">
$(function() {
$('#map_canvas').gmap({ 'center': '40.33238,-3.76546','scrollwheel':false});
$('#map_canvas').gmap('option', 'mapTypeId', google.maps.MapTypeId.SATELLITE);
$('#map_canvas').gmap('option', 'zoom', 17);
});
$("#btnChangeZoom").click(function(){changeZoom()});
function changeZoom(){
$('#map_canvas').gmap('option', 'zoom', 10);
}
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
使用:
$("#map_canvas").gmap({'zoom':7})
Run Code Online (Sandbox Code Playgroud)
当map已经初始化并且不会返回jQuery对象时,可以使用option-method,因此它不可链接(什么将解释你得到的错误).
| 归档时间: |
|
| 查看次数: |
21794 次 |
| 最近记录: |