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
    Vote Rating

    Default 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.

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Gainesville, FL
    Vote Rating


    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!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2

    Think my support is good? Get more personalized support via a support subscription.

    Need more help with your app? Hire Sencha Services

    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
    Paris, France
    Vote Rating


    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 :

    doSomething; //call here a function to get the API asynchronously;
    		            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