当捕获事件“regionChanged”时,地图区域不适合 Titanium 的 MapView

发布于 2024-09-30 18:18:12 字数 1681 浏览 4 评论 0原文

我用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

记忆里有你的影子 2024-10-07 18:18:12

好的。我找到了这个错误的根源。只需要设置regionFit:true并且地图的缩放级别是正确的。

OK. I found the root of this bug. Just need to set regionFit:true and zoom level of map is correct.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文