Results 1 to 3 of 3

Thread: Asynchronous Loading of Google Maps API

  1. #1
    Sencha Premium Member OhmzTech's Avatar
    Join Date
    Jan 2011
    Posts
    42
    Vote Rating
    2
      0  

    Default Asynchronous Loading of Google Maps API

    Recently I decided to change the Google Maps API to load asynchronously in order to improve initial application load time. Unfortunately I found that sometimes this will cause Sencha Touch not to load properly when initializing the map component. After some investigation I found that this is because Sencha Touch looks for the presence of the google.maps variable, and if found, proceeds with loading and rendering the map.

    However when loading Google Maps asynchronously (either by adding the async tag to the script, or using the Google loader with a callback) the remote script immediately returns with an empty google.maps variable while waiting for the main Google Maps API to load. In the rare situations where this initial Google maps file is loaded and Sencha Touch loads the map before the main Google Maps file is loaded there is an error. A possible fix would be to look to the presence of a deeper google.maps variable, such as google.maps.version - which would indicate the file is fully loaded.

    Checking for this google.maps variable happens at the beginning of the renderMap function. A link to the source has been provided below. Please let me know if I can offer any additional information.

    http://docs.sencha.com/touch/2-0/sou...thod-renderMap

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,553
    Answers
    3931
    Vote Rating
    1272
      0  

    Default

    Yeah, if you are going to instantiate an instance of Ext.Map right away then the maps api needs to be loaded sync. If you aren't going to create an instance until after some user interactions then loading async would be ok just have to think about latency in mobile networks.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  3. #3
    Sencha User
    Join Date
    Nov 2011
    Location
    Paris, France
    Posts
    52
    Answers
    1
    Vote Rating
    0
      0  

    Default

    Yes, here is the process I used :

    - Build an empty container (or panel) with a layout:fit. It will contain the map after.
    - When you want do this :

    Code:
    doSomething; //call here a function to get the API asynchronously;
    
    Ext.getCmp('YOURCONTAINER').add(
    	{
    		            xtype: 'map',
    		            mapOptions: {
    		                zoom : 14,
    		                center: whereyouwant 
            },          
            listeners: {
            enjoy Gmap here.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •