Threaded View

  1. #1
    Touch Premium Member
    Join Date
    May 2011
    Posts
    24
    Vote Rating
    0
    Answers
    1
    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);                        
                                  });
                            }
                    }

Thread Participants: 1

Tags for this Thread