即時通訊設法將我的谷歌地圖的中心設置爲我使用Google Map Api V3定義的2個Markes中心。 但它只以第一個標記,即位置標記爲中心。 我有這樣的代碼呈現一個地圖:Sencha Touch 2 + Maps Api - fitbounds()不起作用
openShops : function(data) {
if (Ext.ComponentManager.get('shops-details') == undefined) {
Ext.create('Oxfam.view.ShopsDetails');
}
var shopsDetailsPage = Ext.ComponentManager.get('shops-details');
Ext.Viewport.setActiveItem(shopsDetailsPage);
var bounds;
var map = Ext.create('Ext.Map', {
id : 'shopMap',
xtype : 'map',
useCurrentLocation : {
autoUpdate : false
},
listeners : {
maprender : function(comp, map) {
var image = 'img/oxfamLogoSmall.png';
var locationMarker = new google.maps.Marker({
position : new google.maps.LatLng(this._geo
.getLatitude(), this._geo.getLongitude()),
map : map
});
var shopCoord = new google.maps.LatLng(sessionStorage
.getItem('longitude'), sessionStorage
.getItem('latitude'));
var locCoord = new google.maps.LatLng(this._geo
.getLatitude(), this._geo.getLongitude());
bounds = new google.maps.LatLngBounds();
var shopMarker = new google.maps.Marker({
position : new google.maps.LatLng(sessionStorage
.getItem('longitude'), sessionStorage
.getItem('latitude')),
map : map,
icon : image
});
bounds.extend(shopCoord);
bounds.extend(locCoord);
console.log(shopCoord);
map.fitBounds(bounds);
},
}
});
shopsDetailsPage.setItems(map);
}
的日誌中記錄正確的座標。 的地圖上顯示這樣的: click here to see the map
,但我的願望是這樣的: click here to see my wish
我不知道該怎麼辦,我的意思是即時搜索,因爲時間的解決方案,但在淨心不是每一個解決方案時在我的申請中。
任何人有任何想法我做錯了什麼? 我希望即時張貼每次你需要幫助我的弱點開發經驗的信息;)
您是否嘗試設置地圖的縮放比例?嘗試map.setZoom(n),n在12和16之間。 –
是的,但問題是,縮放級別應該是動態的,因爲每次都是相同的座標。要手動設置縮放級別,可能會在相互之間的寬範圍內顯示2個標記時出現問題,因此您只能看到它們。但感謝您嘗試解決方案 – DenisK
它是幫助:http://stackoverflow.com/questions/3407723/google-maps-fitbounds-is-notworking-properly? –