PDA

View Full Version : JsonReader for Google Direction API response



magoderre
18 Nov 2011, 6:04 AM
Is anybody knows how to set up a Ext.data.JsonReader to handle the response of Google Direction API.

What I did and didn't work :


var jsonreader = new Ext.data.JsonReader({
idProperty:'start_address',
root:'legs',
successProperty:'status',
fields:[
{name:'distance', mapping:'distance'},
{name:'duration', mapping:'duration'},
{name:'adresseFin', mapping:'end_address'},
{name:'positionFin', mapping:'end_location'},
{name:'adresseDebut', mapping:'start_address'},
{name:'positionDebut', mapping:'start_location'},
{name:'etapes', mapping:'steps'},
{name:'escales', mapping:'via_waypoint'}
]
});

var jsonstore = new Ext.data.JsonStore({
autoDestroy: true,
url: request,
storeId: 'GDirectionStore',
reader:jsonreader
});

This is the response Json code:

{
"routes" : [
{
"bounds" : {
"northeast" : {
"lat" : 48.690290,
"lng" : -71.18001000000001
},
"southwest" : {
"lat" : 48.42483000000001,
"lng" : -71.85032000000001
}
},
"copyrights" : "Donnes cartographiques 2011 Google",
"legs" : [
{
"distance" : {
"text" : "47,1 km",
"value" : 47132
},
"duration" : {
"text" : "48 minutes",
"value" : 2886
},
"end_address" : "602-610 1re Rue, L'Ascension-de-Notre-Seigneur, QC G0W 1Y0, Canada",
"end_location" : {
"lat" : 48.690290,
"lng" : -71.671890
},
"start_address" : "Entree De L'Ecole, Mtabetchouan--Lac--la-Croix, QC G8G 1P7, Canada",
"start_location" : {
"lat" : 48.43774000000001,
"lng" : -71.84831000000001
},
"steps" : [
{
"distance" : {
"text" : "0,2 km",
"value" : 167
},
"duration" : {
"text" : "1 minute",
"value" : 19
},
"end_location" : {
"lat" : 48.43835000000001,
"lng" : -71.85032000000001
},
"html_instructions" : "Prendre la direction \u003cb\u003eouest\u003c/b\u003e sur \u003cb\u003eEntree De L'Ecole\u003c/b\u003e vers \u003cb\u003eQC-169 N\u003c/b\u003e",
"polyline" : {
"points" : "{nsfH|[email protected]@[email protected]@"
},
"start_location" : {
"lat" : 48.43774000000001,
"lng" : -71.84831000000001
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "1,0 km",
"value" : 1016
},
"duration" : {
"text" : "2 minutes",
"value" : 90
},
"end_location" : {
"lat" : 48.44166000000001,
"lng" : -71.83750000000001
},
"html_instructions" : "Prendre \u003cb\u003e droite\u003c/b\u003e sur \u003cb\u003eQC-169 S\u003c/b\u003e",
"polyline" : {
"points" : "ursfHngpuLmBiJqFy]iFo^[email protected]{@[eAIS"
},
"start_location" : {
"lat" : 48.43835000000001,
"lng" : -71.85032000000001
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "14,6 km",
"value" : 14624
},
"duration" : {
"text" : "14 minutes",
"value" : 827
},
"end_location" : {
"lat" : 48.465760,
"lng" : -71.678240
},
"html_instructions" : "Continuer sur \u003cb\u003eQC-170 E\u003c/b\u003e",
"polyline" : {
"points" : "[email protected]_A[[email protected]@[email protected]@[email protected][email protected][email protected][email protected]@uHsC{[email protected]@[email protected][email protected]_QuXgIqM}[email protected]}[email protected]@[email protected]{@[email protected]@aA}@sB}@[email protected]}A[sA[[email protected]]wBWaCSsBUiC[[email protected]@{ERqBbBoO`AeJB[zOazAX}DLcEC{[email protected]{FeCmL{[email protected]{AsFsA{H]}DGqB?mC?iBP}[email protected]`@[email protected]|Ga`@|B_N`@mB"
},
"start_location" : {
"lat" : 48.44166000000001,
"lng" : -71.83750000000001
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "24,5 km",
"value" : 24515
},
"duration" : {
"text" : "23 minutes",
"value" : 1389
},
"end_location" : {
"lat" : 48.63252000000001,
"lng" : -71.699990
},
"html_instructions" : "Prendre \u003cb\u003e gauche\u003c/b\u003e sur \u003cb\u003eQC-169 N/QC-170 E\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003eContinuer de suivre QC-169 N\u003c/div\u003e",
"polyline" : {
"points" : "_~xfH~sntL}[email protected]_O{[email protected]{|[email protected]][email protected]_Fe][email protected]@O_`@uMeGwBcEuA{[email protected]@cEwAaQ{FmEuAmFoBsH_C{@[oWaJUIa[[email protected]{@[email protected]{@[email protected]]MgA[[email protected]@[email protected]@[email protected]]QQGCC][email protected]@[email protected]][email protected]{@YgC{@iA][email protected][email protected]][email protected]{C}@uC}@}[email protected]][email protected]@[email protected][[email protected]@R]RONQLMNYZW^[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]][email protected]@[email protected][[email protected]@@[email protected][email protected]@[email protected]@[email protected]@[email protected]@IGGKMWoAwAoC}C{@[email protected]_OaBiB{@iA][email protected][email protected][email protected]@{@[email protected]@U[[email protected]@[email protected]@[email protected]@[email protected]@[email protected]{@[email protected]@[email protected]@[email protected]@[email protected]][email protected]@[email protected]@^[email protected]]@[email protected]@[email protected]_AcEwAoC}@[email protected]@[email protected][email protected][email protected]{@[email protected]@[email protected]][email protected]@[email protected]][email protected]@][email protected]@[email protected]@YQUU[[CCU][email protected]@][email protected]@[email protected]@[[email protected]@[email protected]@yCiA_GuB}@[email protected]@[email protected]@@[@[email protected][email protected]@[email protected][email protected]@[email protected]@[email protected]^[email protected]@[email protected]^{@[email protected]@[email protected]@`[email protected]|@[email protected]@[email protected]@W`AS|@[email protected]]vBw][email protected][email protected]~KkF`[email protected]@[email protected]@[email protected]@[email protected]][email protected]@[email protected]@[email protected]|D"
},
"start_location" : {
"lat" : 48.465760,
"lng" : -71.678240
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "5,0 km",
"value" : 4994
},
"duration" : {
"text" : "7 minutes",
"value" : 414
},
"end_location" : {
"lat" : 48.67451000000001,
"lng" : -71.678190
},
"html_instructions" : "Prendre \u003cb\u003e droite\u003c/b\u003e sur \u003cb\u003eRue Joseph W. Fleury\u003c/b\u003e",
"polyline" : {
"points" : "gpygH|{[email protected]@[email protected][email protected]@[email protected][email protected]@}A}@_cAg\\}[email protected]{@_G{[email protected]@srAs`@"
},
"start_location" : {
"lat" : 48.63252000000001,
"lng" : -71.699990
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "1,8 km",
"value" : 1816
},
"duration" : {
"text" : "2 minutes",
"value" : 147
},
"end_location" : {
"lat" : 48.690290,
"lng" : -71.671890
},
"html_instructions" : "Continuer sur \u003cb\u003e1re Rue\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003eVotre destination se trouvera sur la droite\u003c/div\u003e",
"polyline" : {
"points" : "[email protected]{@[email protected]"
},
"start_location" : {
"lat" : 48.67451000000001,
"lng" : -71.678190
},
"travel_mode" : "DRIVING"
}
],
"via_waypoint" : []
},
{
"distance" : {
"text" : "61,4 km",
"value" : 61353
},
"duration" : {
"text" : "1 heure 10 minutes",
"value" : 4215
},
"end_address" : "1920-1946 Rue Davis, Jonquire, QC G7S 3B6, Canada",
"end_location" : {
"lat" : 48.42483000000001,
"lng" : -71.18242000000001
},
"start_address" : "602-610 1re Rue, L'Ascension-de-Notre-Seigneur, QC G0W 1Y0, Canada",
"start_location" : {
"lat" : 48.690290,
"lng" : -71.671890
},
"steps" : [
{
"distance" : {
"text" : "1,8 km",
"value" : 1816
},
"duration" : {
"text" : "2 minutes",
"value" : 147
},
"end_location" : {
"lat" : 48.67451000000001,
"lng" : -71.678190
},
"html_instructions" : "Prendre la direction \u003cb\u003esud\u003c/b\u003e sur \u003cb\u003e1re Rue\u003c/b\u003e vers \u003cb\u003e3e Av E\u003c/b\u003e",
"polyline" : {
"points" : "[email protected]@rIjC`[email protected]"
},
"start_location" : {
"lat" : 48.690290,
"lng" : -71.671890
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "5,0 km",
"value" : 4994
},
"duration" : {
"text" : "7 minutes",
"value" : 404
},
"end_location" : {
"lat" : 48.63252000000001,
"lng" : -71.699990
},
"html_instructions" : "Continuer sur \u003cb\u003eRue Joseph W. Fleury\u003c/b\u003e",
"polyline" : {
"points" : "uvahHtsntLrrAr`@[email protected]@[email protected]@|BnA~bAf\\|A|@^[email protected]@[email protected]`LrA^dA^[email protected]`[email protected]"
},
"start_location" : {
"lat" : 48.67451000000001,
"lng" : -71.678190
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "7,7 km",
"value" : 7665
},
"duration" : {
"text" : "8 minutes",
"value" : 464
},
"end_location" : {
"lat" : 48.604790,
"lng" : -71.61777000000001
},
"html_instructions" : "Prendre \u003cb\u003e gauche\u003c/b\u003e sur \u003cb\u003eAvenue du Pont N/QC-169 S\u003c/b\u003e",
"polyline" : {
"points" : "gpygH|{[email protected]}[email protected]^{D`@[email protected]\\{[email protected]{[email protected]@[email protected]@V{AP_BL{[email protected][email protected][email protected]{GxAcPXsDNcBN{[email protected]]shD\\[email protected]}@[email protected]@[email protected]@[email protected]}@[email protected]@[email protected]@[email protected]^[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@dDgAtJuC`[email protected]^C`@[email protected]@[email protected]@HbAV|@X~FtBxChA`A`@[email protected]"
},
"start_location" : {
"lat" : 48.63252000000001,
"lng" : -71.699990
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "31,3 km",
"value" : 31291
},
"duration" : {
"text" : "29 minutes",
"value" : 1765
},
"end_location" : {
"lat" : 48.507310,
"lng" : -71.27524000000001
},
"html_instructions" : "Prendre \u003cb\u003e gauche\u003c/b\u003e sur \u003cb\u003eQC-172 E\u003c/b\u003e (panneaux vers \u003cb\u003eSaint-Nazaire/Chicoutimi\u003c/b\u003e)",
"polyline" : {
"points" : "}btgH`[email protected]}@ZqApAcGdB{H`[email protected][email protected]~AyG|@[email protected]@[email protected]@[email protected][email protected]}[email protected]@`@[email protected]}[email protected]@gB^{[email protected]}A`@}[email protected]@J}@[email protected]@P}@[email protected]@[email protected][email protected]@J[[email protected]@[email protected]^}@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[@]@[email protected]@[email protected]{[email protected]@[email protected]@[email protected]][email protected][email protected]@[email protected]@yB`@aB\\yAReAP}A`AaI|[email protected]@[email protected]`@[email protected]@[email protected]@[email protected]@[email protected][email protected]@[email protected]_BV}AV{[email protected][email protected]}[email protected]@[email protected]{DVaCRcBXeCZeC\\oCRiB\\eCZeCTiBRoBZyBTkB\\kCXsBReB\\qC|@[email protected]^[email protected]`@oClAoI`[email protected]@}[email protected]\\aEBU|[email protected]@H{@LaALcAPcAP}@R_APaAXoARcAP{@P}@[email protected]}[email protected]@[email protected]@[email protected][email protected]@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@O_AYmA{@[email protected]}@{[email protected]}@eDaA}[email protected]{B}[email protected][email protected]@{[email protected][{[email protected]@[email protected]{[email protected][email protected]}@[email protected]}[email protected]@RyAZaBfAmEzBcJnAqEdAmDdBgGzB{[email protected]@fAiD~DsM|E}[email protected]@}[email protected]@[email protected]@[email protected]@[email protected]@[email protected][email protected][email protected]@kADiAFeAJmBXgCZqB^{CHcBFiBA_CI}[email protected]@[email protected]?_BB}@[email protected][email protected]{[email protected]{[email protected][J[L[\\[email protected]`@[email protected]@[email protected]@[email protected]@][email protected][[email protected]@nAeA|B_C`[email protected][email protected]@`@iAX}@[email protected]@[email protected]\\[email protected]@@[email protected]@[email protected]@[email protected][email protected]]hB][email protected]@jD{A`HcDlCqA|@[email protected]^[email protected]@\\[\\][email protected]@[email protected][email protected]@}A`@gB^[email protected]@[email protected]@[email protected]@aE|@eH`@aD\\[email protected]@[email protected]@}[email protected]@uAL][email protected]@qA|@{[email protected][email protected]@|@[email protected]|@[email protected]`[email protected]@[email protected]@xCZ`[email protected]@`[email protected][email protected][email protected]@[email protected]@[email protected]|@XNDZFxATbAJ|AB`@[email protected]@E|@[email protected][email protected]@[email protected]}@bBkAnA}@[email protected]@[email protected][email protected]{CzAeChAiBnB}CjB}CnB}C`B_CfDaEhB}[email protected]@[email protected]`@}@[email protected]\\[email protected]_AN}@nBwM"
},
"start_location" : {
"lat" : 48.604790,
"lng" : -71.61777000000001
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "4,3 km",
"value" : 4315
},
"duration" : {
"text" : "6 minutes",
"value" : 356
},
"end_location" : {
"lat" : 48.471080,
"lng" : -71.277230
},
"html_instructions" : "Prendre \u003cb\u003e droite\u003c/b\u003e sur \u003cb\u003eRoute Coulombe\u003c/b\u003e (panneaux vers \u003cb\u003eSHIPSHAW/JONQUI?RE\u003c/b\u003e)",
"polyline" : {
"points" : "uaagHf}[email protected][email protected]@[email protected]@[email protected]^[email protected]^[email protected]@[email protected]@Q|@[email protected]~CA|BA`@@[email protected]@P\\[email protected]@[email protected]|[email protected]@XTRNTN\\[email protected]@N^J\\J\\@^B`@?`@A`@[email protected]|[email protected]@nB[fB]|[email protected]@zA][email protected]}@fB[jAQ^[email protected]@[email protected]@fB\\bC`@[email protected]@|[email protected]^[email protected]@[email protected]@[email protected]"
},
"start_location" : {
"lat" : 48.507310,
"lng" : -71.27524000000001
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "2,4 km",
"value" : 2385
},
"duration" : {
"text" : "4 minutes",
"value" : 235
},
"end_location" : {
"lat" : 48.45760000000001,
"lng" : -71.25544000000001
},
"html_instructions" : "Prendre \u003cb\u003e gauche\u003c/b\u003e sur \u003cb\u003eRoute Saint Lonard\u003c/b\u003e",
"polyline" : {
"points" : "g_zfHti`rLfF_PjBaGbBgFvAsElC_JbC{HzA{[email protected]^[email protected]\\[email protected]@LQLO\\[email protected]^]`@[email protected]@[email protected]@K`@I|@[email protected]@GLCNEJEJE`@Q\\U^[DEV[T][email protected][email protected]@[email protected]@[email protected]@[email protected]|@[email protected]@_E"
},
"start_location" : {
"lat" : 48.471080,
"lng" : -71.277230
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "2,1 km",
"value" : 2145
},
"duration" : {
"text" : "3 minutes",
"value" : 170
},
"end_location" : {
"lat" : 48.44410000000001,
"lng" : -71.23870000000001
},
"html_instructions" : "Continuer sur \u003cb\u003eChemin de Saint Lonard/Route de la Dam Deux\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003eContinuer de suivre Route de la Dam Deux\u003c/div\u003e",
"polyline" : {
"points" : "_kwfHna|[email protected]@[email protected]@[email protected]@[email protected]@[email protected][email protected]|@[email protected]`A}[email protected]@[email protected][email protected]]NURUbAFxC`@[email protected]|FdArAP`@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]\\W^[^]^[email protected]~B_DdB{B"
},
"start_location" : {
"lat" : 48.45760000000001,
"lng" : -71.25544000000001
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "1,4 km",
"value" : 1410
},
"duration" : {
"text" : "2 minutes",
"value" : 146
},
"end_location" : {
"lat" : 48.43197000000001,
"lng" : -71.237740
},
"html_instructions" : "Prendre lgrement \u003cb\u003e droite\u003c/b\u003e sur \u003cb\u003eRue Price\u003c/b\u003e",
"polyline" : {
"points" : "[email protected]?H?H?|@[email protected]\\dANlC^[email protected]@[email protected]@[email protected]^[email protected]@[email protected]@[email protected]`@[email protected]\\[email protected]@NBRDbAX`[email protected]`@F^@[email protected][email protected][email protected]@[email protected]"
},
"start_location" : {
"lat" : 48.44410000000001,
"lng" : -71.23870000000001
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "4,3 km",
"value" : 4336
},
"duration" : {
"text" : "7 minutes",
"value" : 411
},
"end_location" : {
"lat" : 48.432740,
"lng" : -71.18005000000001
},
"html_instructions" : "Prendre \u003cb\u003e gauche\u003c/b\u003e sur \u003cb\u003eBoulevard du Saguenay\u003c/b\u003e (panneaux vers \u003cb\u003eAutoroute 70/QC-372/kenogami/Chicoutimi\u003c/b\u003e)",
"polyline" : {
"points" : "yjrfHzrxqLB[[email protected]@[email protected]}[email protected]][email protected][email protected][[email protected]@[email protected]@[email protected][email protected]@[email protected][email protected]@[email protected]?}@[email protected][email protected]@EeAKkC[[email protected][email protected][email protected]@][email protected]@O?G?O?M?I"
},
"start_location" : {
"lat" : 48.43197000000001,
"lng" : -71.237740
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0,8 km",
"value" : 848
},
"duration" : {
"text" : "1 minute",
"value" : 86
},
"end_location" : {
"lat" : 48.425470,
"lng" : -71.18127000000001
},
"html_instructions" : "Au rond-point, prendre la \u003cb\u003e1re\u003c/b\u003e sortie sur \u003cb\u003eBoulevard Mellon\u003c/b\u003e",
"polyline" : {
"points" : "[email protected]@[email protected][email protected]\\[email protected]@QRG|@W"
},
"start_location" : {
"lat" : 48.432740,
"lng" : -71.18005000000001
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0,1 km",
"value" : 100
},
"duration" : {
"text" : "1 minute",
"value" : 17
},
"end_location" : {
"lat" : 48.42525000000001,
"lng" : -71.182580
},
"html_instructions" : "Prendre \u003cb\u003e droite\u003c/b\u003e sur \u003cb\u003eRue Marion\u003c/b\u003e",
"polyline" : {
"points" : "ebqfH|qmqLTbCT`C"
},
"start_location" : {
"lat" : 48.425470,
"lng" : -71.18127000000001
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "48 m",
"value" : 48
},
"duration" : {
"text" : "1 minute",
"value" : 14
},
"end_location" : {
"lat" : 48.42483000000001,
"lng" : -71.18242000000001
},
"html_instructions" : "Prendre \u003cb\u003e gauche\u003c/b\u003e sur \u003cb\u003eRue Davis\u003c/b\u003e",
"polyline" : {
"points" : "y`[email protected]"
},
"start_location" : {
"lat" : 48.42525000000001,
"lng" : -71.182580
},
"travel_mode" : "DRIVING"
}
],
"via_waypoint" : []
}
],
"overview_polyline" : {
"points" : "{nsfH|[email protected][email protected]@{[email protected]}[email protected]@aO}U{[email protected]`AgEuK_CiL}[email protected]@[email protected]}[email protected][email protected]{WwVqIwkA{`@[email protected]{[email protected]}[email protected]{`@i[{KqJc`@}[email protected]@[email protected]{T|XoBnAaBHw]kL{KkDmR}HqQkHkFsGyD}CsJ}[email protected]_CiCoByO{[email protected]?aOtDoMhEwEfCwD`[email protected][}BzT}[email protected]|VgBbJgG|[email protected]{[email protected]@|DsCkA{HeCmQeF{[email protected]}eAe^[email protected]@NdNfEtdDfaAdC~B~KfRlDjC|eAd^[email protected]@}[email protected]{GbCmVbK}bAfB}[email protected]|F{[email protected]@`[email protected]}GfCUbFPrLpDzEjBhCnBnDmNn]y`BzFsVdDiS|EyXrBaHvCqKtAuJjBa][email protected]{NtHkU~AsI`[email protected]{[email protected]|[email protected]\\[email protected][email protected]@HcI][email protected]{LeIwQsK_RgFaLgBuOmB{YiCo`@MmP|Bg`ApAuQrS}[email protected]@[email protected]}[email protected]@[email protected][email protected]^}[email protected]{@[email protected]`DyBbH{[email protected]{[email protected]}[email protected]@dG}[email protected]@|[email protected]{J`[email protected][email protected][email protected]|GmJvBqCtBkApFeB~E{[email protected]|][email protected]|[email protected]{HrOyCzF\\[email protected]~BpA|[email protected][email protected][[email protected]}[email protected]|[email protected]@C|[email protected]@[email protected]@[email protected]@[email protected]@[email protected]_K}[email protected][email protected]~HzGfA`KgC`AY|@WTbCT`[email protected]"
},
"summary" : "QC-172 E",
"warnings" : [],
"waypoint_order" : [ 0 ]
}
],
"status" : "OK"
}

mitchellsimoens
18 Nov 2011, 1:58 PM
Does it support ScriptTagProxy?

You may need to create an extension of JsonReader to modify the incoming JSON so that it can consume it.