Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-2673] iPhone Map: Adding regionChanged listener causes map region to change

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionCannot Reproduce
Resolution Date2012-07-26T14:26:22.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsiOS
Labelsn/a
ReporterJonathan Harlap
AssigneeNeeraj Gupta
Created2011-04-15T03:26:35.000+0000
Updated2012-07-26T21:13:50.000+0000

Description

When creating a map view, if you add a regionChanged listener then it changes the displayed region, as illustrated by http://developer.appcelerator.com/question/77481/map-region-doesnt-fit-in-mapview-of-titanium-when-catch-event-regionchanged"> http://developer.appcelerator.com/question/77481/map-region-doesnt-...

This is because when firing the event the code alters the region object when it should simply read it.
TiMapView.m in the github master as of today reads (around line 516):

if ([self.proxy _hasListeners:@"regionChanged"])
    {
        region = [mapView region];

It should not be modifying the region instance variable, so simply changing this line to read MKCoordinateRegion region = [mapView region]; solves the problem.

Comments

  1. Stephen Tramer 2012-07-26

    Can't reproduce in SDK 2.2.0.014b86f on iPhone Sim 5.1. Test code:
       var win = Titanium.UI.createWindow();
        
       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)
       {
        
       });
       win.open();
       

JSON Source