Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-5470] iOS: regionChanged is fired 4 times on initialization

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionWon't Do
Resolution Date2020-01-09T19:25:40.000+0000
Affected Version/sRelease 1.8.0, Release 2.0.1, Release 3.1.0
Fix Version/sn/a
ComponentsiOS
LabelsSupportTeam, api
ReporterAlan Leard
AssigneeEric Merriman
Created2011-10-07T18:50:41.000+0000
Updated2020-01-09T19:25:40.000+0000

Description

the regionChanged event is fired 4 times when you first open a mapview. See log output in example:
var win1 = Titanium.UI.createWindow();

var mapView = Ti.Map.createView({
  mapType: Ti.Map.STANDARD_TYPE,
  region:{
    latitude:33.74511, longitude:-84.38993,
    latitudeDelta:0.5, longitudeDelta:0.5
  },
  animate:true,
  regionFit:true,
  userLocation:true
});

var count = 1

mapView.addEventListener('regionChanged', function(e) {
  var latitude = e.latitude;
  var longitude = e.longitude;
  var latitudeDelta = e.latitudeDelta;
  var longitudeDelta = e.longitudeDelta;
  Ti.API.info(count+" latitude: " + latitude + " longitude: " + longitude + " latitudeDelta: " + latitudeDelta + " longitudeDelta: " + longitudeDelta);
  count++;
});

win1.add(mapView);

win1.open();

Extra info

As a collateral effect of this, adding the listener significantly changes the lat/long delta that I specified (therefore, changing the specified geolocation that centers the map).

Community Discussion

http://developer.appcelerator.com/question/135900/regionchanged-odd-behavior

Comments

  1. Frank Apap 2012-04-23

    Beyond the event firing 4 times, the act of adding the regionChanged listener changes the view of the map significantly. See the log output below: // this sets the background color of the master UIView (when there are no windows/tab groups on it) Titanium.UI.setBackgroundColor('#000'); var win1 = Titanium.UI.createWindow({ title:'Tab 1', backgroundColor:'#fff' }); var lastLat = 40.6826867; var lastLng= -73.4474855; var dLat= 0.46578809902344176; var dLng=0.8684262167968768; Ti.API.info("Starting map location lat "+lastLat+" lon "+lastLng+ " delta lat "+dLat + " detla lng "+dLng); var region = {latitude:lastLat, longitude:lastLng, latitudeDelta:dLat, longitudeDelta:dLng}; var mapview = Titanium.Map.createView({ mapType: Titanium.Map.STANDARD_TYPE, region: region, animate:false, regionFit:false, userLocation:false }); mapview.addEventListener('regionChanged',function(e){ Ti.API.info("regionEvent"); Titanium.API.info('New Map Location: long ' + e.longitude + ' lat ' + e.latitude + ' longDelta ' + e.longitudeDelta + ' latDelta '+e.latitudeDelta); }); win1.add(mapview); win1.open(); /* Log output without touching anything [INFO] Starting map location lat 40.6826867 lon -73.4474855 delta lat 0.46578809902344176 detla lng 0.8684262167968768 [DEBUG] application booted in 171.029985 ms [INFO] regionEvent [INFO] New Map Location: long -73.443603515625 lat 40.680638025212914 longDelta 1.0986328125 latDelta 0.8331513920235949 [INFO] regionEvent [INFO] New Map Location: long -73.443603515625 lat 40.680638025212914 longDelta 4.6142578125 latDelta 4.665321024142628 [INFO] regionEvent [INFO] New Map Location: long -73.443603515625 lat 40.680638025212914 longDelta 3.515625 latDelta 3.832318306517699 */
  2. Junaid Younus 2012-05-16

    Tested with 2.0.1GA2 on the iOS simulator, the event gets fired 3 times for me.
  3. jithinpv 2013-05-08

    issue reproduces event fired 3 times Tested with Titanium Studio, build: 3.0.1.201212181159 Titanium SDK version: 3.1.0 iOS iPhone Simulator: iOS SDK version: 6.0
  4. Alan Hutton 2020-01-09

    It has been decided that this issue should be closed as “Won’t do.” This issue is out of date with our current supported SDK release (7.5.2.GA as of the date of closure), and out of date with mobile OS versions. Updating, or creating code may not reproduce the issue reported, or be a valid test case. If community members feel that the issue is still valid, please create a new ticket. Please reference this closed ticket number, include SDK used, comments, and code that demonstrates/reproduces the issue.

JSON Source