Map region doesn't fit in MapView of Titanium when catch event 'regionChanged'
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. But now, the map zoom level is suddenly maximum. (Oh, it's normal in Simulator, so please check in real phone to see this bug). 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?
3 Answers
-
Try setting regionFit to false.
-
regionFit has nothing to do with it. This is a bug in Titanium which I've just reported in lighthouse at https://appcelerator.lighthouseapp.com/projects/32238-titanium-mobile/tickets/2673-iphone-map-adding-regionchanged-listener-causes-map-region-to-change
A simple solution is to do
mapview.setLocation(boston);
after adding the event listener. -
any help for this problem?