title: Titanium Appcelerator Mapview Takes a Long Time to Open
body: <p>I am creating an iOS app in Titanium Appcelerator that contains a dashboard window and 2 additional windows. One of them contains a mapview that takes ~3 seconds to load, which is a long time to be looking at a blank screen.</p>
  
  <p>In the Appcelerator forums, <a href="http://developer.appcelerator.com/question/97671/geolocation-refreshing-to-current-location" rel="nofollow">this</a> post someone has posted asking how to refresh to a user's position, only when it changes by a certain amount, which I have implemented. My current implementation is as follows:</p>
  
  <ol>
  <li><p>Set the distance filter so that it only refreshes on major moves</p>
  
  <pre><code>Titanium.Geolocation.distanceFilter = 10;
  </code></pre></li>
  <li><p>Create a mapview at an insignificant starting location (0,0) and add it to the window</p>
  
  <pre><code>var mapview = Titanium.Map.createView({
      mapType: Titanium.Map.STANDARD_TYPE,
      region: {latitude: 0, longitude: 0, latitudeDelta:0.05, longitudeDelta:0.05},
      animate:false,
      regionFit:true,
      userLocation:false
  });
  
  win.add(mapview);
  </code></pre></li>
  <li><p>Get the users location and set the mapview's location to it</p>
  
  <pre><code>//Should only go once
  Titanium.Geolocation.getCurrentPosition(function(e)
  {
      if (e.error)
      {
          alert('Cannot get your current location');
          return;
      }
  
      var longitude = e.coords.longitude;
      var latitude = e.coords.latitude;
      var altitude = e.coords.altitude;
      var heading = e.coords.heading;
      var accuracy = e.coords.accuracy;
      var speed = e.coords.speed;
      var timestamp = e.coords.timestamp;
      var altitudeAccuracy = e.coords.altitudeAccuracy;
  
      var current = {
              latitude : latitude,
              longitude : longitude,
              latitudeDelta : .05,
              longitudeDelta : .05
          };
      mapview.setLocation(current);
      mapview.userLocation = true;
  });
  </code></pre></li>
  </ol>
  
  <p>I just want the map to load fast. If it takes a few seconds to pinpoint the user's location, that's fine. But having the user look at a blank screen for 3 seconds is terrible. Is there a way around this?</p>
  
  <p>I have also set:</p>
  
  <pre><code>Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST;
  </code></pre>
  
  <p>if it makes a difference.</p>
  
  <p><strong>EDIT:</strong> I commented out the part where I am getting the users location and the map still takes the same amount of time to load. I think the problem has to do with the fact that I am opening my map.js file before I create it.</p>
  
  <p>In my app.js file, I call map.open(). Then at the top of my map.js file, I do:</p>
  
  <pre><code>var win = Ti.UI.currentWindow;
  </code></pre>
  
  <p>and then I construct the map and add it. I don't know of a way to keep my architecture but preload the map. Is this possible?</p>