[英]jquery-ui-map how to set zoom level and center the map
如何在此代碼中設置縮放級別
$(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();
});
我嘗試添加縮放比例:6,但它不會使地圖居中,並且我正在嘗試使用地理位置對地圖進行居中
所以我想我的問題是我如何將地圖居中到地理位置坐標並設置縮放級別
PS我注定是假的
提前致謝
嘗試這個:
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)
}
});
};
或者,您可以設置bounds: false
並通過$("#map_canvas").('option', 'center', point);
設置地圖的中心$("#map_canvas").('option', 'center', point);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.