1. #1
    Sencha Premium Member
    Join Date
    Jan 2011
    Posts
    39
    Vote Rating
    1
    OhmzTech is on a distinguished road

      0  

    Default Unanswered: Asynchronous Loading of Google Maps API

    Unanswered: 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 - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,026
    Answers
    3493
    Vote Rating
    850
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      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 @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Nov 2011
    Location
    Paris, France
    Posts
    46
    Answers
    1
    Vote Rating
    0
    Arekkk is on a distinguished road

      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.