当捕获事件“regionChanged”时,地图区域不适合 Titanium 的 MapView
我用 Titanium (iPhone) 编写了一个演示地图视图。这是我从 KitchenSink 获得的代码:
var win = Titanium.UI.currentWindow;
var annotation = Titanium.Map.createAnnotation({
latitude:42.334537,
longitude:-71.170101,
title:"Boston College",
subtitle:'Newton Campus, Chestnut Hill, MA',
animate:true,
leftButton:'../images/atlanta.jpg'
});
var boston = {latitude:42.334537,longitude:-71.170101,latitudeDelta:0.010, longitudeDelta:0.018};
//
// CREATE MAP VIEW
//
var mapview = Titanium.Map.createView({
mapType: Titanium.Map.STANDARD_TYPE,
region: boston,
animate:true,
regionFit:true,
userLocation:true,
annotations:[annotation]
});
win.add(mapview);
它在 iPhone 模拟器和真实手机上都运行良好。 问题是,当我捕获事件“regionChanged”时,地图区域是错误的。我的代码是:
var win = Titanium.UI.currentWindow;
var annotation = Titanium.Map.createAnnotation({
latitude:42.334537,
longitude:-71.170101,
title:"Boston College",
subtitle:'Newton Campus, Chestnut Hill, MA',
animate:true,
leftButton:'../images/atlanta.jpg'
});
var boston = {latitude:42.334537,longitude:-71.170101,latitudeDelta:0.010, longitudeDelta:0.018};
//
// CREATE MAP VIEW
//
var mapview = Titanium.Map.createView({
mapType: Titanium.Map.STANDARD_TYPE,
region: boston,
animate:true,
regionFit:true,
userLocation:true,
annotations:[annotation]
});
win.add(mapview);
// map view click event listener
mapview.addEventListener('regionChanged',function(evt)
{
});
在这个事件中,我什至没有写任何东西。在模拟器中,它与第一种情况一样运行良好,但在真实手机中,地图缩放级别突然达到最大。虽然我设置了 latitudeDelta=1,但地图的缩放级别仍然是最大放大,就好像 latitudeDelta=0.001 一样。
那么,这个错误的根源是什么?有人可以帮助我吗?
I write a demo mapview in Titanium (iPhone). Here's the code I get from KitchenSink:
var win = Titanium.UI.currentWindow;
var annotation = Titanium.Map.createAnnotation({
latitude:42.334537,
longitude:-71.170101,
title:"Boston College",
subtitle:'Newton Campus, Chestnut Hill, MA',
animate:true,
leftButton:'../images/atlanta.jpg'
});
var boston = {latitude:42.334537,longitude:-71.170101,latitudeDelta:0.010, longitudeDelta:0.018};
//
// CREATE MAP VIEW
//
var mapview = Titanium.Map.createView({
mapType: Titanium.Map.STANDARD_TYPE,
region: boston,
animate:true,
regionFit:true,
userLocation:true,
annotations:[annotation]
});
win.add(mapview);
It runs well on both iPhone Simulator as well as in real phone.
The problem is, when I catch event 'regionChanged', the map region is wrong. My code is:
var win = Titanium.UI.currentWindow;
var annotation = Titanium.Map.createAnnotation({
latitude:42.334537,
longitude:-71.170101,
title:"Boston College",
subtitle:'Newton Campus, Chestnut Hill, MA',
animate:true,
leftButton:'../images/atlanta.jpg'
});
var boston = {latitude:42.334537,longitude:-71.170101,latitudeDelta:0.010, longitudeDelta:0.018};
//
// CREATE MAP VIEW
//
var mapview = Titanium.Map.createView({
mapType: Titanium.Map.STANDARD_TYPE,
region: boston,
animate:true,
regionFit:true,
userLocation:true,
annotations:[annotation]
});
win.add(mapview);
// map view click event listener
mapview.addEventListener('regionChanged',function(evt)
{
});
In this event, I even didn't write anything. In Simulator, it works well as the first case, but in real phone, the map zoom level is suddenly maximum. Although I set latitudeDelta=1, the zoom level of map is still zoom-in maximum as if latitudeDelta=0.001.
So, what's the root of this bug? Anyone can help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的。我找到了这个错误的根源。只需要设置
regionFit:true
并且地图的缩放级别是正确的。OK. I found the root of this bug. Just need to set
regionFit:true
and zoom level of map is correct.