[英]jquery-ui-map how to set zoom level and center the map
how do I set the zoom level in this code 如何在此代码中设置缩放级别
$(function() {
$('#map_canvas').gmap({ 'disableDefaultUI':true, 'callback': function() {
var self = this;
$.getJSON( 'location1.php', function(data) {
console.log(data);
$.each( data[0].markers, function(i, marker) {
self.addMarker({ 'position': new google.maps.LatLng(marker.latitude, marker.longitude) } ).click(function() {
self.openInfoWindow({ 'content': marker.content }, this);
});
});
});
self.getCurrentPosition(function(position, status) {
if ( status === 'OK' ) {
self.set('clientPosition', new google.maps.LatLng(position.coords.latitude, position.coords.longitude));
self.addMarker({'position': self.get('clientPosition'), 'bounds': false});
self.addShape('Circle', { 'strokeWeight': 0, 'fillColor': "#008595", 'fillOpacity': 0.25, 'center': self.get('clientPosition'), 'radius': 24140.16, clickable: false });
}
});
}}).load();
});
i tried adding zoom: 6 but it wont center the map, and i am trying to center the map using geolocation 我尝试添加缩放比例:6,但它不会使地图居中,并且我正在尝试使用地理位置对地图进行居中
so i guess my question would be how do i center the map to the geolocation coordinates and set the zoom level 所以我想我的问题是我如何将地图居中到地理位置坐标并设置缩放级别
PS i have bounds to false PS我注定是假的
thanks in advance 提前致谢
try this: 尝试这个:
self.getCurrentPosition(function(position, status) {
if ( status === 'OK' ) {
var point = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
self.addMarker({'position': point, 'bounds': true});
self.addShape('Circle', { 'strokeWeight': 0, 'fillColor': "#008595", 'fillOpacity': 0.25, 'center': point, 'radius': 24140.16, clickable: false });
self.gmap('option', 'zoom', 12)
}
});
};
Alternatively, you could leave bounds: false
and set the map's center by $("#map_canvas").('option', 'center', point);
或者,您可以设置
bounds: false
并通过$("#map_canvas").('option', 'center', point);
设置地图的中心$("#map_canvas").('option', 'center', point);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.