我试图通过Google Map Api V3将我的谷歌地图的中心设置为我的2个定义的Markes。 但它只是第一个标记,即位置标记。 我有这个渲染地图的代码:
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
我不知道该怎么做,我的意思是我从几个小时开始寻找解决方案,但网络中的每个解决方案都不适用于我的应用程序..
任何人都知道我做错了什么? 我希望我发布您需要的所有信息,以帮助我的弱开发经验;)
答案 0 :(得分:1)
这让我觉得你的经纬度是错误的:
var shopCoord = new google.maps.LatLng(sessionStorage
.getItem('longitude'), sessionStorage
.getItem('latitude'));
再来一次:
var shopMarker = new google.maps.Marker({
position : new google.maps.LatLng(sessionStorage
.getItem('longitude'), sessionStorage
.getItem('latitude')),
map : map,
icon : image
});
如果是这种情况(并且您不仅仅错误地标记了'sessionStorage'对象中的变量),那么这将影响边界,这可能是问题。
答案 1 :(得分:0)
得到了答案。 谢谢大家。
问题是,
useCurrentLocation : {
autoUpdate : false
},
自动使locationMarker居中。
我通过使用没有sencha touch实现定位方法的html5地理位置来解决问题。
感谢您的帮助!