Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am working with the Directions API using python.

mapApi = GoogleMaps(API_KEY)
directionsObj.routes = mapApi.directions(directionsObj.source, directionsObj.destination)
print "directionsObj.routesssss", directionsObj.routes['routes']

I used the above code to get the Json response file of Directions API and I stored the Json to mongoengine(the database used). Now in the terminal I get the following result when I run the above code.

Json file:

[{u'overview_polyline': {u'points': u'yiv{@a~~pMPv@KDRnAfAdHeBl@o@ZaAh@}Bx@}CdAyBn@oDfAgEtAv@pEpBbLlBnItCxMlBlHdBpGzB|HXhAl@tBXv@`@`AoAr@iKbF{CxAcAl@]T_@^Q^GVIf@UdAO`@[j@YXo@b@aCrAsAn@{IhD{At@yCfBqAv@_@\\kAxByErKeB|DKR_CzCsBhCcAfAk@h@[Re@Js@JgD\\aBFeAAcAIq@OqAe@}@Qg@Ce@Bs@Ls@Ts@r@s@~@k@hAmCHeDDkAFsBJkI`@_BJyG\\s^bB}QvAa\\xCcEZaGl@yCV_Q~ABNh@Et@bBDVCJ?XL|@X`AXz@Rd@^r@`@t@X|@F^Dt@Jt@Xf@NTPl@Ff@?j@VnBJr@I@MFu@d@YPy@\\{Bl@}Aj@e@Vw@`@WFW@c@?a@E{@IU?q@JwB`@oB`@cARyABaCFs@FaAJOBbAnE?VEl@E^BRvAfCJJLFjAf@QDgEbAqAPoB^}@JkAReCl@iAZsBZGDCJDh@EDaD^Rv@b@bC\\tBVxB\\xCPdAPl@\\jAXv@zBvChAtAr@~@dCpC'}, u'copyrights': u'Map data \xa92012 Google', u'warnings': [], u'legs': [{u'distance': {u'text': u'11.1 km', u'value': 11118}, u'end_address': u'Kaloor, Ernakulam, Kerala, India', u'via_waypoint': [], u'start_address': u'Thrippunithura, Kerala, India', u'duration': {u'text': u'19 mins', u'value': 1126}, u'steps': [{u'html_instructions': u'Head west', u'distance': {u'text': u'33 m', u'value': 33}, u'polyline': {u'points': u'yiv{@a~~pMPv@'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 9.949890000000002, u'lng': 76.34929000000001}, u'duration': {u'text': u'1 min', u'value': 4}, u'end_location': {u'lat': 9.949800000000003, u'lng': 76.34901}}, {u'html_instructions': u'Turn right toward Ernakulam-Ettumanoor Rd/SH 15', u'distance': {u'text': u'8 m', u'value': 8}, u'polyline': {u'points': u'giv{@i|~pMKD'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 9.949800000000003, u'lng': 76.34901}, u'duration': {u'text': u'1 min', u'value': 11}, u'end_location': {u'lat': 9.949860000000001, u'lng': 76.34898000000001}}, {u'html_instructions': u'Take the 1st left toward Ernakulam-Ettumanoor Rd/SH 15', u'distance': {u'text': u'0.2 km', u'value': 211}, u'polyline': {u'points': u'siv{@c|~pMJp@F\\D\\RjA^|BL|@'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 9.949860000000001, u'lng': 76.34898000000001}, u'duration': {u'text': u'1 min', u'value': 28}, u'end_location': {u'lat': 9.949400000000002, u'lng': 76.34711}}, {u'html_instructions': u'Turn right onto Ernakulam-Ettumanoor Rd/SH 15Pass by Abhayam (on the right in 400m)', u'distance': {u'text': u'0.6 km', u'value': 608}, u'polyline': {u'points': u'wfv{@mp~pMcA\\a@N[NSJg@VYP[LaBj@m@PoBr@{@V}@V}Bp@q@T]JiDhA'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 9.949400000000002, u'lng': 76.34711}, u'duration': {u'text': u'1 min', u'value': 71}, u'end_location': {u'lat': 9.95439, u'lng': 76.34486000000001}}, {u'html_instructions': u'Turn left at SN Jct onto Kochi - Madurai - Tondi Point Hwy/Kochi - Madurai - Tondi Point Highway/NH 85Pass by ICICI Bank (on the left)', u'distance': {u'text': u'1.5 km', u'value': 1536}, u'polyline': {u'points': u'}ew{@kb~pM@D^xBTnA?@pB`L?@x@xDr@tCJf@x@zDJd@bAnEj@xBBJDNv@vCT|@b@|ABJf@hB~@zCz@`DJ\\Lj@^rAL`@JXL\\FRXl@'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 9.95439, u'lng': 76.34486000000001}, u'duration': {u'text': u'2 mins', u'value': 112}, u'end_location': {u'lat': 9.949900000000001, u'lng': 76.33162}}, {u'html_instructions': u'Turn right at Petta Jct onto Ernakulam Ettumanoor Rd', u'distance': {u'text': u'54 m', u'value': 54}, u'polyline': {u'points': u'{iv{@so{pMo@^_@R'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 9.949900000000001, u'lng': 76.33162}, u'duration': {u'text': u'1 min', u'value': 59}, u'end_location': {u'lat': 9.9503, u'lng': 76.33136}}, {u'html_instructions': u'Continue onto SH 15 Ernakulam -Ettumanoor HwyPass by Reliance Petrol Pump (on the right in 1.5km)', u'distance': {u'text': u'2.5 km', u'value': 2516}, u'polyline': {u'points': u'klv{@_n{pMuBbAcBx@uBbAy@`@OFqAn@g@TQJWLOJQJIFEBC@KHGDGFGFGDGHEFEHA@CJEJAJEPCTKh@IZGRGLIPGHABGJIHONIFe@ZMFe@Vi@Zc@VQHULSHWLs@XaEzA{An@IBe@Tu@^}@h@{A|@WNMHYPQJKHKHCBCDEFKP]n@[n@e@dAQ\\s@`BmBlEg@hAe@dAO\\GNEHEHEFyBrCmA~Ae@h@_@`@c@d@[XONKHOHSDQDWF[BcALcBNy@Bg@Bi@?[A]Ce@E]GSGk@Se@QOESEMCKAUAQAS@Q@YDYFWH[J'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 9.9503, u'lng': 76.33136}, u'duration': {u'text': u'3 mins', u'value': 153}, u'end_location': {u'lat': 9.967500000000001, u'lng': 76.31912000000001}}, {u'html_instructions': u'Continue onto Sahodaran Ayyappan Rd', u'distance': {u'text': u'0.1 km', u'value': 134}, u'polyline': {u'points': u'{wy{@oaypMGHIFQPONKJQTKNILa@t@IR'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 9.967500000000001, u'lng': 76.31912000000001}, u'duration': {u'text': u'1 min', u'value': 59}, u'end_location': {u'lat': 9.968240000000002, u'lng': 76.31817000000001}}, {u'html_instructions': u'Turn right at Vyttila Jct onto NH 66Pass by Muthoot Motors (on the left in 1.6km)', u'distance': {u'text': u'2.8 km', u'value': 2771}, u'polyline': {u'points': u'o|y{@q{xpMS?yBHeDDkAFm@BeAFgCJcEToAHO@yEVo@DC?K?q@DK@qLh@cOp@wIn@OB}ALwCTmNpA{D\\qEb@e@DcEZaGl@sAJeAJuALcFb@yEd@k@F'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 9.968240000000002, u'lng': 76.31817000000001}, u'duration': {u'text': u'3 mins', u'value': 205}, u'end_location': {u'lat': 9.99295, u'lng': 76.31493}}, {u'html_instructions': u'Turn left toward NH66 Service Road', u'distance': {u'text': u'9 m', u'value': 9}, u'polyline': {u'points': u'}v~{@igxpM?@BL'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 9.99295, u'lng': 76.31493}, u'duration': {u'text': u'1 min', u'value': 11}, u'end_location': {u'lat': 9.992930000000001, u'lng': 76.31485}}, {u'html_instructions': u'Turn left onto NH66 Service Road', u'distance': {u'text': u'24 m', u'value': 24}, u'polyline': {u'points': u'yv~{@yfxpMd@EB?'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 9.992930000000001, u'lng': 76.31485}, u'duration': {u'text': u'1 min', u'value': 11}, u'end_location': {u'lat': 9.99272, u'lng': 76.31488}}, {u'html_instructions': u'Take the 1st right onto Puthiya Rd', u'distance': {u'text': u'0.6 km', u'value': 621}, u'polyline': {u'points': u'ou~{@_gxpMBFh@jABHBD@F@F?D@@?@?@A@AD?B?F?D?F?D@BHj@@F?BDJHVHXPh@FPHTHNP^LRRXLZFPDJDLDPBLBPB\\@V@N@LBJBJ@BFJHLDHBFJLFTHV@F@B@L@L?H?J?H?J@NBTLv@BPJr@'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 9.99272, u'lng': 76.31488}, u'duration': {u'text': u'1 min', u'value': 51}, u'end_location': {u'lat': 9.990900000000002, u'lng': 76.30962000000001}}, {u'html_instructions': u'Turn right at Puthiya Road Junction onto Thammanam RdPass by Thammanam Mosque (on the left)', u'distance': {u'text': u'0.6 km', u'value': 623}, u'polyline': {u'points': u'cj~{@cfwpMI@GBEBOJOHIFKFKHMFg@RQHWH[Ha@He@No@Tm@TYNKFQHSLGBIDMBIBK@K?S?O?OAQC]E]CIAK@I@OBMBI@_APw@NoAT_@JQDYFKBK@S?'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 9.990900000000002, u'lng': 76.30962000000001}, u'duration': {u'text': u'2 mins', u'value': 98}, u'end_location': {u'lat': 9.996120000000001, u'lng': 76.30793000000001}}, {u'html_instructions': u'Continue onto Mahakavi Vailoppilli Rd', u'distance': {u'text': u'0.2 km', u'value': 187}, u'polyline': {u'points': u'wj_|@q{vpMa@@Q?Q@eBB[BYBYB_@Da@DOB'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 9.996120000000001, u'lng': 76.30793000000001}, u'duration': {u'text': u'1 min', u'value': 42}, u'end_location': {u'lat': 9.99779, u'lng': 76.30775000000003}}, {u'html_instructions': u'Turn left onto Indira Road', u'distance': {u'text': u'0.3 km', u'value': 343}, u'polyline': {u'points': u'eu_|@mzvpMbAnE@JAJC^ALEX?D@F@JBFrA~BDDDDFBDBjAf@'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 9.99779, u'lng': 76.30775000000003}, u'duration': {u'text': u'1 min', u'value': 45}, u'end_location': {u'lat': 9.996540000000001, u'lng': 76.30512}}, {u'html_instructions': u'Turn right onto St. Martin Road', u'distance': {u'text': u'0.6 km', u'value': 641}, u'polyline': {u'points': u'km_|@_jvpMQDgEbAqAP_@FoAVI@s@HkAReCl@m@P[Hc@HoAPC@CBADADDb@?DABC@aD^'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 9.996540000000001, u'lng': 76.30512}, u'duration': {u'text': u'1 min', u'value': 89}, u'end_location': {u'lat': 10.00178, u'lng': 76.30334}}, {u'html_instructions': u'Turn left at Worldwide IPR Services onto NH 47Pass by Juma Masjid (on the left)Destination will be on the left', u'distance': {u'text': u'0.8 km', u'value': 799}, u'polyline': {u'points': u'cn`|@{~upMRv@RnANr@BRX`BRxAB^D`@P~ABP@DF^Hd@@DNf@Rp@HXHXN\\`@j@xAjBJL|@fAr@~@dCpC'}, u'travel_mode': u'DRIVING', u'start_location': {u'lat': 10.00178, u'lng': 76.30334}, u'duration': {u'text': u'1 min', u'value': 77}, u'end_location': {u'lat': 9.998700000000001, u'lng': 76.29695000000001}}], u'start_location': {u'lat': 9.949890000000002, u'lng': 76.34929000000001}, u'end_location': {u'lat': 9.998700000000001, u'lng': 76.29695000000001}}], u'bounds': {u'northeast': {u'lat': 10.00178, u'lng': 76.34929000000001}, u'southwest': {u'lat': 9.949400000000002, u'lng': 76.29695000000001}}, u'waypoint_order': [], u'summary': u'NH 66'}]

How to parse the above Json file so that I can get only the start_address,end_address, u'html_instructions only.

share|improve this question
Thid is not about the Google Maps API 3. – Marcelo Nov 3 '12 at 7:00
Sorry sir. and thankyou for correcting – ToothLess Nov 3 '12 at 8:51
you're welcome, and you don't need to call me "sir" ;-) – Marcelo Nov 3 '12 at 8:57
Ok I found the answer – ToothLess Nov 3 '12 at 9:20

1 Answer

up vote 0 down vote accepted

This code worked for geting the start_address,end_address, html_instructions:

for leg in directionsObj.route['legs']:
    startAddress = leg['start_address']
    print "Start Address:", startAddress
    endAddress = leg['end_address']
    print "End Address:", endAddress
    for step in leg['steps']:
        html_instructions = step['html_instructions']
        print "html instructions", html_instructions
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.