-
2 Dec 2012 1:03 PM #1
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();
In 4.1 Ext.data.DataProxy is gone so I was trying this using Ext.data.proxy.Ajax:PHP Code:.....
.....
tbar: [{
xtype: "gx_geocodercombo",
width: 250,
layer: locationLayer,
displayField: "formatted_address",
store: new Ext.data.JsonStore({
root: null,
fields: [
"formatted_address",
{name: "lonlat", convert: function(v, rec) {
var latLng = rec.geometry.location;
return [latLng.lng(), latLng.lat()];
}},
{name: "bounds", convert: function(v, rec) {
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(action, rs, params, reader, callback, scope, options) {
geocoder.geocode({address: operation.params.q}, function(results, status) {
var readerResult = reader.readRecords(results);
console.log(readerResult);
callback.call(scope, readerResult, options, !!readerResult);
});
}
}))({api: {read: true}})
})
}]
readerResult returns a constructor containing the correct json but I'm also getting the error:PHP Code:
proxy: new (Ext.extend(Ext.data.proxy.Ajax, {
doRequest: function(operation, callback, scope) {
geocoder.geocode({address: operation.params.q}, function(results, status) {
var readerResult = scope.proxy.reader.readRecords(results);
console.log(readerResult);
callback.call(scope, readerResult, options, !!readerResult);
});
}
}))({api: {read: true}})
})
Any idea what I'm doing wrong? I am totally on the wrong track here?PHP Code:Uncaught TypeError: Object [object Object] has no method 'getResultSet' Store.js 1148
Thanks in advance.Last edited by jnw; 24 Jan 2013 at 10:00 AM. Reason: Solved
-
Best Answer Posted by jnw
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); }); } }
-
4 Dec 2012 7:34 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,121
- Vote Rating
- 453
- Answers
- 3160
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
________________
http://www.JSONPLint.com - Source to lint your JSONP!
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 almost in print!
When posting code, please use BBCode's CODE tags.
-
6 Dec 2012 1:41 PM #3
I'm wondering now do I even need a new class? I simplified things to this:
I still have the issue: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); }); } }
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?HTML Code:Uncaught TypeError: Object [object Object] has no method 'getResultSet'
Thanks much!
-
24 Jan 2013 10:05 AM #4
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); }); } }


Reply With Quote