1. #1
    Touch Premium Member
    Join Date
    May 2011
    Posts
    24
    Answers
    1
    Vote Rating
    0
    jnw is on a distinguished road

      0  

    Default Answered: SOLVED: Google geocode and doRequest with Ext.data.proxy.Ajax?

    Answered: SOLVED: Google geocode and doRequest with Ext.data.proxy.Ajax?


    hello,

    I'm having trouble porting over this small piece of code that performs a google geocode request in an extended ComboBox (from GeoExt). In Ext JS 3.4 this works perfectly:

    PHP Code:
    var geocoder = new google.maps.Geocoder(); 
    PHP Code:
    .....
    .....
    tbar: [{
        
    xtype"gx_geocodercombo",
        
    width250,
        
    layerlocationLayer,
        
    displayField"formatted_address",
        
    store: new Ext.data.JsonStore({
            
    rootnull,
            
    fields: [
                
    "formatted_address",
                {
    name"lonlat"convert: function(vrec) {
                    var 
    latLng rec.geometry.location;
                    return [
    latLng.lng(), latLng.lat()];
                }},
                {
    name"bounds"convert: function(vrec) {
                    var 
    ne rec.geometry.viewport.getNorthEast(),
                        
    sw rec.geometry.viewport.getSouthWest();
                    return [
    sw.lng(), sw.lat(), ne.lng(), ne.lat()];
                }}
            ],
            
    proxy: new (Ext.extend(Ext.data.DataProxy, {
                
    doRequest: function(actionrsparamsreadercallbackscopeoptions) {
                                      
    geocoder.geocode({addressoperation.params.q}, function(resultsstatus) {
                                                var 
    readerResult reader.readRecords(results);
                                                 
    console.log(readerResult);
                                            
    callback.call(scopereaderResultoptions, !!readerResult);                        
                                        });
                            }
                 }))({
    api: {readtrue}})
             })
    }] 
    In 4.1 Ext.data.DataProxy is gone so I was trying this using Ext.data.proxy.Ajax:

    PHP Code:

    proxy
    : new (Ext.extend(Ext.data.proxy.Ajax, {
                    
    doRequest: function(operationcallbackscope) {
                              
    geocoder.geocode({addressoperation.params.q}, function(resultsstatus) {
                                            var 
    readerResult scope.proxy.reader.readRecords(results);
                                
    console.log(readerResult);
                                    
    callback.call(scopereaderResultoptions, !!readerResult);                        
                                });
                    }
         }))({
    api: {readtrue}})
     }) 
    readerResult returns a constructor containing the correct json but I'm also getting the error:

    PHP Code:
    Uncaught TypeErrorObject [object Objecthas no method 'getResultSet' Store.js 1148 
    Any idea what I'm doing wrong? I am totally on the wrong track here?

    Thanks in advance.
    Last edited by jnw; 24 Jan 2013 at 10:00 AM. Reason: Solved

  2. Not sure I've done this correctly but it is working for me now.
    I didn't find much out there on how to do this so here is what I came up with. Hope it helps someone.

    Code:
                     proxy: {
                            type: 'jsonp',
                            api: {read: true},
                        
                            doRequest: function(operation, callback, scope) {
                                geocoder.geocode({address: operation.params.q}, function(results, status) {
        
                                    var readerResult = scope.proxy.reader.readRecords(results);
                                    scope.loadRecords(readerResult.records, operation);
                                    scope.loading = false;
                                    scope.fireEvent('load', this, readerResult.records, true);
                                    //console.log(readerResult);                        
                                  });
                            }
                    }

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,207
    Answers
    3517
    Vote Rating
    856
    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


    You shouldn't override a method when creating an instance, you should make a new class using Ext.define.
    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.

  4. #3
    Touch Premium Member
    Join Date
    May 2011
    Posts
    24
    Answers
    1
    Vote Rating
    0
    jnw is on a distinguished road

      0  

    Default


    I'm wondering now do I even need a new class? I simplified things to this:

    Code:
             proxy: {
                   type: 'ajax',
                   api: {
                           read: true
                     },
                     reader: {
                               type: 'json',
                               root: null
                    },
    
                    doRequest: function(operation, callback, scope) {
                        
                                geocoder.geocode({address: operation.params.q}, function(results, status) {
                                
                                        var readerResult = scope.proxy.reader.readRecords(results);
                                         console.log(readerResult);   //geocode data looks ok here    
                                
                                callback.call(scope, readerResult, operation);
    
                                });
    
                      }
             }
    I still have the issue:
    HTML Code:
    Uncaught TypeError: Object [object Object] has no method 'getResultSet'
    Am I simplifying this too much and I do need a new class? I haven't found many examples of the callback from doRequest. Is this off track?

    Thanks much!

  5. #4
    Touch Premium Member
    Join Date
    May 2011
    Posts
    24
    Answers
    1
    Vote Rating
    0
    jnw is on a distinguished road

      0  

    Default


    Not sure I've done this correctly but it is working for me now.
    I didn't find much out there on how to do this so here is what I came up with. Hope it helps someone.

    Code:
                     proxy: {
                            type: 'jsonp',
                            api: {read: true},
                        
                            doRequest: function(operation, callback, scope) {
                                geocoder.geocode({address: operation.params.q}, function(results, status) {
        
                                    var readerResult = scope.proxy.reader.readRecords(results);
                                    scope.loadRecords(readerResult.records, operation);
                                    scope.loading = false;
                                    scope.fireEvent('load', this, readerResult.records, true);
                                    //console.log(readerResult);                        
                                  });
                            }
                    }

Thread Participants: 1

Tags for this Thread