I'm currently working on a project using google maps Directions API on Android.
When i make any direction request i get a response such as this one
I'm actually able to decode the point's to get a List of subsequent LatLng coordinates to reach. Now i need to understand for each path between two subsequent LatLng points if it's an highway street(you had to pay to get there) or a normal street.
I don't think there's any way of doing so from this response. Is there any other parameter i can use to show this information? or maybe is there any other api i can use?
{
"geocoded_waypoints" : [
{
"geocoder_status" : "OK",
"place_id" : "ChIJBVcXiwukOxMRaaVJcZxIGXQ",
"types" : [ "locality", "political" ]
},
{
"geocoder_status" : "OK",
"place_id" : "ChIJ76RLkZW8OxMRpBS0rnKK0dI",
"types" : [ "locality", "political" ]
}
],
"routes" : [
{
"bounds" : {
"northeast" : {
"lat" : 40.7912565,
"lng" : 14.498954
},
"southwest" : {
"lat" : 40.7461626,
"lng" : 14.3675599
}
},
"copyrights" : "Dati mappa ©2018 Google",
"legs" : [
{
"distance" : {
"text" : "14,6 km",
"value" : 14606
},
"duration" : {
"text" : "21 min",
"value" : 1244
},
"end_address" : "80045 Pompei NA, Italia",
"end_location" : {
"lat" : 40.7461626,
"lng" : 14.498954
},
"start_address" : "80059 Torre del Greco NA, Italia",
"start_location" : {
"lat" : 40.7893898,
"lng" : 14.3675599
},
"steps" : [
{
"distance" : {
"text" : "0,3 km",
"value" : 260
},
"duration" : {
"text" : "1 min",
"value" : 71
},
"end_location" : {
"lat" : 40.7912565,
"lng" : 14.3694103
},
"html_instructions" : "Procedi in direzione \u003cb\u003enordest\u003c/b\u003e da \u003cb\u003eStrada Statale 18 Tirrena Inferiore\u003c/b\u003e/\u003cb\u003eSR18\u003c/b\u003e verso \u003cb\u003eTraversa I Vittorio Veneto\u003c/b\u003e",
"polyline" : {
"points" : "ut}wFgduvAe#c#WUKMa#]MOi#i#kCkCeAeA"
},
"start_location" : {
"lat" : 40.7893898,
"lng" : 14.3675599
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0,9 km",
"value" : 932
},
"duration" : {
"text" : "3 min",
"value" : 162
},
"end_location" : {
"lat" : 40.7846057,
"lng" : 14.3756157
},
"html_instructions" : "Svolta a \u003cb\u003edestra\u003c/b\u003e per rimanere su \u003cb\u003eStrada Statale 18 Tirrena Inferiore\u003c/b\u003e/\u003cb\u003eSR18\u003c/b\u003e",
"maneuver" : "turn-right",
"polyline" : {
"points" : "k`~wFyouvA~#}AhA{AdCcDhBaCd#o#tByCnAaBt#_ALQHMRUBCPOb#Qf#Gb#EVEr#KPGTG^WFILMNMLM`AeAp#s#RWLIJGNEJETAl#GXB"
},
"start_location" : {
"lat" : 40.7912565,
"lng" : 14.3694103
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "1,0 km",
"value" : 973
},
"duration" : {
"text" : "2 min",
"value" : 123
},
"end_location" : {
"lat" : 40.7908857,
"lng" : 14.3829714
},
"html_instructions" : "Svolta a \u003cb\u003esinistra\u003c/b\u003e e prendi \u003cb\u003eVia Cavallo\u003c/b\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "yv|wFsvvvACOCICICGO_#w#qAKOCGCICICISmAG_#CMEMCGAE_AoAkCgDoB}Bi#o#i#c#GGEECEYg#e#{#UYY[y#eAk#m#OQUWQKMEs#NMDSBK?IAECSOa#k#]a#ECMGSISQECg#q#IG{#qAAGQ_#"
},
"start_location" : {
"lat" : 40.7846057,
"lng" : 14.3756157
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0,2 km",
"value" : 202
},
"duration" : {
"text" : "1 min",
"value" : 35
},
"end_location" : {
"lat" : 40.7897602,
"lng" : 14.3848068
},
"html_instructions" : "Alla rotonda prendi la \u003cb\u003e1ª\u003c/b\u003e uscita e prendi lo svincolo \u003cb\u003eA3\u003c/b\u003e/\u003cb\u003eE45\u003c/b\u003e per \u003cb\u003eAutostrade\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003eStrada a pedaggio parziale\u003c/div\u003e",
"maneuver" : "roundabout-right",
"polyline" : {
"points" : "a~}wFqdxvA#C?C?E?E?C?ETe#b#y#x#}AbA}Af#u#"
},
"start_location" : {
"lat" : 40.7908857,
"lng" : 14.3829714
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "9,9 km",
"value" : 9941
},
"duration" : {
"text" : "7 min",
"value" : 402
},
"end_location" : {
"lat" : 40.7495621,
"lng" : 14.476954
},
"html_instructions" : "Mantieni la \u003cb\u003esinistra\u003c/b\u003e al bivio, segui le indicazioni per \u003cb\u003eE45\u003c/b\u003e/\u003cb\u003eSalerno\u003c/b\u003e/\u003cb\u003eReggio C.\u003c/b\u003e ed entra in \u003cb\u003eA3\u003c/b\u003e/\u003cb\u003eE45\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003eStrada a pedaggio\u003c/div\u003e",
"maneuver" : "fork-left",
"polyline" : {
"points" : "_w}wFapxvAV_#DEPQLIPIVKRGPEPCPAX?H#N#VFPDNHPHVRPPJLLRLRP\\Vv#j#bBn#|BH`#DZBX#T#X?PAN?LCXCRCRGVGPGRKVMTKRMLGHIFIDGBI#I#GAIAGAGEIEEEEGEKEKAKCI?K?K?I#K?G#KBMBGDM#??APy#dBeDTc#Tg#Vg#zEoJJUFMTa#^u#p#iAb#w#x#qAn#{#rA_B~#aAbB}A`DqCfByAJKdBuAdA_A`A}#j#s#zAuBt#iAXg#Ta#Te#HQLYNa#Rw#^yAf#sBdAiERw#p#}Bz#eDl#gCr#yCj#eC`AcELe#Je#ViAt#}Cl#aCZwATeAp#{Ch#_CpAsFr#iCt#oCb#_B|#mDLi#J[H[tA_Fl#wBFUrA{E~#gDl#wB^wA~BoIDQFSdCyIf#iBVaANi#l#gCx#aEb#kBBMh#eCDYLc#XcATs#Ng#Lc#Na#Ja#Z{AJe#H_#F]XqA^wBVyAJq#Ns#Po#n#_CRq#p#oCz#aEZqADO?CFQrA{FBIDSBKJ_#r#oClA{EZsAFWFWfA{Ev#}Dx#wD?CH[?AF[b#kBlBkIdAcFdAmE|#uDZuAHe#XyAJw#H}#HmBF_DBiD#_#?a#HyHDmEHgEDu#Bk#Fi#Fw#^cCJk#Lk#ZgArAwDPg#p#aBdBiF?A#CFOh#{An#iBH[t#qB#GFOBIJ[^cA|#aC^cAjAwCt#kBfAoCjAuC#A`AaC~C}HpAcDn#aBv#wBt#sB`AsCbBcFBEJY?AJYfAsCzAcE|AgEvBaGx#aCzB}FlDgJXs#n#gB"
},
"start_location" : {
"lat" : 40.7897602,
"lng" : 14.3848068
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0,2 km",
"value" : 212
},
"duration" : {
"text" : "1 min",
"value" : 32
},
"end_location" : {
"lat" : 40.7482728,
"lng" : 14.4784155
},
"html_instructions" : "Prendi l'uscita \u003cb\u003ePompei\u003c/b\u003e verso \u003cb\u003ePompei\u003c/b\u003e/\u003cb\u003ePompei Ovest\u003c/b\u003e",
"maneuver" : "ramp-right",
"polyline" : {
"points" : "w{uwF}ojwARKBCBEL_#Vk#\\q#`#{#Rk#Pc#HQDCDCFCDCF#D#D###FBVN"
},
"start_location" : {
"lat" : 40.7495621,
"lng" : 14.476954
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "1,0 km",
"value" : 991
},
"duration" : {
"text" : "3 min",
"value" : 169
},
"end_location" : {
"lat" : 40.7471718,
"lng" : 14.489806
},
"html_instructions" : "Svolta a \u003cb\u003esinistra\u003c/b\u003e e prendi \u003cb\u003eStrada Statale 18 Tirrena Inferiore\u003c/b\u003e/\u003cb\u003eSR18\u003c/b\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "usuwFcyjwATwAPuAJw#JaAJcAPcBDc#Hk#Lm#TcA`#iBr#cDN{#j#qD?GFcAB{#IaBq#yNSiEEkABWAeA"
},
"start_location" : {
"lat" : 40.7482728,
"lng" : 14.4784155
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0,5 km",
"value" : 520
},
"duration" : {
"text" : "2 min",
"value" : 102
},
"end_location" : {
"lat" : 40.74907,
"lng" : 14.4952359
},
"html_instructions" : "Alla rotonda prendi la \u003cb\u003e2ª\u003c/b\u003e uscita e prendi \u003cb\u003eVia Plinio\u003c/b\u003e",
"maneuver" : "roundabout-right",
"polyline" : {
"points" : "yluwFi`mwA#??A#A?A#??A?A?A?A?A?A?A?A?AA??A?AA??AA??AA??AA?A?A?A?A??#A?KQGCeAsCQi#kCuGMs#OaA?Cg#kEi#kEEa#"
},
"start_location" : {
"lat" : 40.7471718,
"lng" : 14.489806
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0,2 km",
"value" : 198
},
"duration" : {
"text" : "1 min",
"value" : 62
},
"end_location" : {
"lat" : 40.7493801,
"lng" : 14.4975391
},
"html_instructions" : "Continua su \u003cb\u003eVia Roma\u003c/b\u003e",
"polyline" : {
"points" : "uxuwFgbnwAEW?EKu#Kw#KaAGeACa#Aa#EsB"
},
"start_location" : {
"lat" : 40.74907,
"lng" : 14.4952359
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0,3 km",
"value" : 324
},
"duration" : {
"text" : "1 min",
"value" : 78
},
"end_location" : {
"lat" : 40.7466072,
"lng" : 14.4987269
},
"html_instructions" : "Svolta a \u003cb\u003edestra\u003c/b\u003e e prendi \u003cb\u003eVia Vittorio Emanuele\u003c/b\u003e",
"maneuver" : "turn-right",
"polyline" : {
"points" : "szuwFspnwAlC{#zAc#rC_ArBm#ZMZQ"
},
"start_location" : {
"lat" : 40.7493801,
"lng" : 14.4975391
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "53 m",
"value" : 53
},
"duration" : {
"text" : "1 min",
"value" : 8
},
"end_location" : {
"lat" : 40.7461626,
"lng" : 14.498954
},
"html_instructions" : "Continua su \u003cb\u003eVia Antonio Morese\u003c/b\u003e",
"polyline" : {
"points" : "iiuwFaxnwAdAc#RG"
},
"start_location" : {
"lat" : 40.7466072,
"lng" : 14.4987269
},
"travel_mode" : "DRIVING"
}
],
"traffic_speed_entry" : [],
"via_waypoint" : []
}
],
"overview_polyline" : {
"points" : "ut}wFgduvAkBeBiGkG~#}AhA{AnFeHzCiEdCaDn#y#POb#QjAMjAQf#OdA}#`CgC`#a#ZM`#Gl#GXBGYGQgAqBOWGSWwAUcAaAuA{FeHi#o#i#c#MM]m#{#uAoCaDUWQKMEs#Na#HUAYS_AmASKg#[m#u#eAyASg##G?Ux#_Bx#}AbA}A~#uAVW^Sj#Sb#Ij#AXBh#L`#Rh#d#X`#^p#bAzCx#~CHt#Bn#EhAGf#Oh#Sj#Yh#UVSLQDQ?QCQKKMKWEm#Bi#Nc#P{#zBiEtGuMnBoD|AiCbC{CbD_DhGkFpBaBfC}BfCiDnAqBbAsBb#yAfAmExAaGlBcHnEkRfBsHpC{LzBsJhByGzBsIvJ}]rGoU~#kD|#qDjCaMR}#n#wBx#oCx#_Ex#iEb#kC`#cBbAqDp#oCz#aE`#aB~A{GhAoExB_JfA{Ev#}Dx#{Dt#eDrDoPbCcKd#{Bd#qCRkDJiIPiQN}FJuAf#{DXwAZgArAwDbAiCnB_GrDqKhEaLjEsKbJeUlBkFdDwJZ{#xJaXtD_KfE{Kn#gBRKFId#kA~#mBd#oANULGLATHVNTwA\\mCn#mGVyAv#mDbA_Fj#yDJ_C{#{QYuGBWAeA#??A#C#GEQEAC?A?MOGCeAsC}C_I]uBg#oEu#kGWmBSgCEcAEsBlC{#nFcBnC{#tB}#"
},
"summary" : "A3/E45",
"warnings" : [],
"waypoint_order" : []
}
],
"status" : "OK"
}
You can set optional parameter ...&avoid=tolls... (or highways or both: avoid=tolls|highways) in Directions Request, e.g.:
https://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal&avoid=tolls&mode=bicycling&key=[YOUR_KEY]
to get response without that kind of roads.
UPDATE
From this answer of Rishi Singh: for toll roads you can find "toll" (or "toll road") tag in html_instructions subnode of steps node in response JSON, like:
...
"steps": [
{
"distance": {
"text": "42.5 mi",
"value": 68323
},
"duration": {
"text": "38 mins",
"value": 2254
},
"end_location": {
"lat": 42.4352772,
"lng": -87.95487469999999
},
"html_instructions": "Merge onto <b>I-94 E</b><div style=\"font-size:0.9em\">Partial toll road</div><div style=\"font-size:0.9em\">Entering Illinois</div>",
"maneuver": "merge",
"polyline": {
...
So you mark not only toll part, but whole "step" with toll road.
Also, take a look at this answer of Emad Dehnavi.
UPDATE 2
May be it's possible to create "subrequest" for step with "Partial toll road" tag and get more precisely response with totally "Toll road" part... Or combine responses with &avoid=tolls and without that restriction and get toll parts this way.
UPDATE 3
And there is one more workaround: you can use Google Maps Styled Map and set custom style (e.g. red color for road with controlled access and blue for highways) something like on picture:
then get points on road and use approach like in this answer to test color on stylized map at that point in addition to JSON analyze, may be you determine highway/toll road more precisely.
Related
When I run the first Google API url with origin, destination and waypoints, it returns
https://maps.googleapis.com/maps/api/directions/json?origin=9.6614981,80.02554649999999&waypoints=6.9040322,79.948803&destination=6.053518500000001,6.053518500000001%7C&sensor=false
{
"geocoded_waypoints" : [
{},
{},
{
"geocoder_status" : "ZERO_RESULTS"
}
],
"routes" : [],
"status" : "NOT_FOUND"
}
But when I run this second url, this works perfectly fine.
https://maps.googleapis.com/maps/api/directions/json?origin=6.9146871,79.9711348&waypoint=6.9040322,79.948803%7C&destination=6.9058482,79.9248089&sensor=false
{
"geocoded_waypoints" : [
{
"geocoder_status" : "OK",
"place_id" : "ChIJnbKVwttW4joR96eguc1D88A",
"types" : [ "route" ]
},
{
"geocoder_status" : "OK",
"place_id" : "ChIJnVoMvVZX4joRcAOUeZGMTUA",
"types" : [ "street_address" ]
}
],
"routes" : [
{
"bounds" : {
"northeast" : {
"lat" : 6.916328699999999,
"lng" : 79.972351
},
"southwest" : {
"lat" : 6.9033429,
"lng" : 79.9247644
}
},
"copyrights" : "Map data ©2017 Google",
"legs" : [
{
"distance" : {
"text" : "6.9 km",
"value" : 6928
},
"duration" : {
"text" : "18 mins",
"value" : 1109
},
"end_address" : "19/7 Bogahahena Rd, Sri Jayawardenepura Kotte 10120, Sri Lanka",
"end_location" : {
"lat" : 6.9058178,
"lng" : 79.9247644
},
"start_address" : "Pasan Mawatha, Malabe, Sri Lanka",
"start_location" : {
"lat" : 6.914893699999999,
"lng" : 79.9702508
},
"steps" : [
{
"distance" : {
"text" : "0.2 km",
"value" : 167
},
"duration" : {
"text" : "1 min",
"value" : 50
},
"end_location" : {
"lat" : 6.916328699999999,
"lng" : 79.97066389999999
},
"html_instructions" : "Head \u003cb\u003enorth\u003c/b\u003e on \u003cb\u003ePasan Mawatha\u003c/b\u003e toward \u003cb\u003eWelivita Rd\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003ePass by Boys Hostel (on the right)\u003c/div\u003e",
"polyline" : {
"points" : "aqei#aebgNg#GWEOEUKaAY{AWK?O?"
},
"start_location" : {
"lat" : 6.914893699999999,
"lng" : 79.9702508
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0.2 km",
"value" : 202
},
"duration" : {
"text" : "1 min",
"value" : 42
},
"end_location" : {
"lat" : 6.915699,
"lng" : 79.972351
},
"html_instructions" : "Turn \u003cb\u003eright\u003c/b\u003e onto \u003cb\u003eWelivita Rd\u003c/b\u003e",
"maneuver" : "turn-right",
"polyline" : {
"points" : "azei#sgbgNBg#BQHc#J[Va#LQHOFOLm#He#No#"
},
"start_location" : {
"lat" : 6.916328699999999,
"lng" : 79.97066389999999
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "2.8 km",
"value" : 2757
},
"duration" : {
"text" : "7 mins",
"value" : 426
},
"end_location" : {
"lat" : 6.903943,
"lng" : 79.9549985
},
"html_instructions" : "Turn \u003cb\u003eright\u003c/b\u003e at Petti Kade onto \u003cb\u003eB263\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003ePass by Super Como Technologies (on the right)\u003c/div\u003e",
"maneuver" : "turn-right",
"polyline" : {
"points" : "cvei#erbgN|#J`#DbAHb##hBFn#?t##^?rAAhAA\\AX?b#?R#RBTBPBPDXH\\H\\Jz#X|Cr#LFHBJDNHLDLHLJPJNLJNLNJRLTHTHV|#lC`#fAHTDPDPBJ#J#T#TAVAVCVIb#KZKVO\\KTM`#AJALALAN#RBZDZF^FZFVHPFPFNFDPRJHVNXLrAj#FBn#Zn#XXNVNTLPJXPXVd#b###PRZ`#JRL\\Rl#^`AJZDFXp#DLPd#Xn#JVNX\\j#b#p#^l#h#fA\\z#Pb#t#xBVp#ZhAVlANv#ZpADd#BZ#L#d##TANCTE^Gh#Mp#Qz#APIZI\\EZI`#Ef#Ej#Ef#Gz#Cd#"
},
"start_location" : {
"lat" : 6.915699,
"lng" : 79.972351
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "3.7 km",
"value" : 3722
},
"duration" : {
"text" : "9 mins",
"value" : 564
},
"end_location" : {
"lat" : 6.9052345,
"lng" : 79.9251951
},
"html_instructions" : "At \u003cb\u003eMalabe\u003c/b\u003e, continue onto \u003cb\u003eකෝට්ටේ - බෝපේ පාර\u003c/b\u003e/\u003cb\u003eB240\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003ePass by Megacity (on the left in 350 m)\u003c/div\u003e",
"polyline" : {
"points" : "slci#we_gNEj#Cl#CPCTERKZM\\Ql#Wn#Wz#Oz#GZALAN?Z?N#L?HBPBVZnBD\\#L#J#L#H?J?F?HAH?HCFAHEJGLMZKV}#bBUb#s#jAm#jAKPKNOZARQd#Qp#M`#[hASr#a#~AYfA]dAM^CJEFMNOPOHi#Xc#Tc#X_#Tq#h#OLOPQROPEJKRELADERMl#I`#I^I`#APCL?JAP?N#H#RDPBJPh#FNDNFPBH#JBLBNBV?#D\\FrAD~#Bv##V?R?`#?^?`DAd#An#Cj#EzAAx#A`AAnA#`##T#TBPFPDNDNFPJVVv#N\\b#hAVr#JXHVFTFTJl#Ff#Fj#B^#V?Z?^?b#?n#ErDChAEl#C^G`#UpAMh#Q~#Ox#EX?TETCLAJAJ?L?H#H#FBDBFDDDFBBJHFBFFLJNFNBJ#RBN#J?V#p#BL#XDXFRFPFVJTLRLPNXTHJJJFNDN#L#NALCPERGVw#~DMf#EPABAJCPAN#L#LDPFLJPHFJHJHPHNLLH^V"
},
"start_location" : {
"lat" : 6.903943,
"lng" : 79.9549985
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "80 m",
"value" : 80
},
"duration" : {
"text" : "1 min",
"value" : 27
},
"end_location" : {
"lat" : 6.9058178,
"lng" : 79.9247644
},
"html_instructions" : "Turn \u003cb\u003eright\u003c/b\u003e at okvel auto care onto \u003cb\u003eBogahahena Rd\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003ePass by Waruna Motors (on the left)\u003c/div\u003e\u003cdiv style=\"font-size:0.9em\"\u003eDestination will be on the right\u003c/div\u003e",
"maneuver" : "turn-right",
"polyline" : {
"points" : "utci#okyfNc#\\IFgAp#"
},
"start_location" : {
"lat" : 6.9052345,
"lng" : 79.9251951
},
"travel_mode" : "DRIVING"
}
],
"traffic_speed_entry" : [],
"via_waypoint" : []
}
],
"overview_polyline" : {
"points" : "aqei#aebgN_AMe#QaAY{AW[?Fy#T_Ad#s#P_#VsANo#|#JdBNlCHxE?dDCnALfBd#z#X|Cr#VJv#^^VZ\\Xb#Vj#fAdDj#|APz#Bj#Cn#Mz#Wr#[r#Ol#CZ?b#Hv#Nz#Ph#N`#XXb#XdDxAvBfAj#\\~#z#RTf#t#lAhDv#lBd#fAl#dAbA~AfAbCfA|Cr#zBf#dCZpADd#Dh#Bz#SnBk#zCOx#OhAWtDIxAGf#q#zBo#jBWvAC\\?j#H`Ad#fDBj#Ed#]~#iAzBiAnBuAhCARQd#_#rAkBdHu#xB]`#y#b#gAn#qA~#_#^a#d#Yr#g#bCOlAA`#B\\H\\Xx#Rv#Jv#LpBHvB#lBAfEEzAGtCCpCBv#Df#ZbAvAvDt#zBRbANrADrB?rAI|FIlA]rB_#hBUrA?TETEXAX#RNZ\\XTR^Jz#FhADf#Fl#Nh#RtA`ATVL^B\\E^sArGMr#?\\F^R^TPz#j#^Vc#\\qAx#"
},
"summary" : "B263 and කෝට්ටේ - බෝපේ පාර/B240",
"warnings" : [],
"waypoint_order" : []
}
],
"status" : "OK"
}
Whats the difference when comparing both URL's, i can't seem to find any. Please help!
I'm trying to draw the routes between both origin and destination through a waypoint. How can I achieve this ??
Thank you!
Check your destination Latlng . The first link you are asking navigation from Sri Lanka to Nigeria(6.053518500000001,6.05351850000000). I think you are adding mismatch destination , ie, You are using the same latitude value for longitude also. Check your code.
I am working on a reverse geo-coding functionality in Android.
When I do a getFromLocation(0, 0, 1) using the geocoder class from Google API call for example it returns ZERO RESULTS and the address length is zero.
But for example when I go to Google Maps on the web and I right click on location 0,0 it says "Atlantic Ocean". This also work when I drop a pin in the Google Maps App in Android.
Is there a way to get "Atlantic Ocean" or similar programatically from the coordinates 0,0 ? When I say 0,0 it also applies to other coordinates that are in the middle of the sea.
Yes, there is a way to get the name of the sea corresponding to the coordinates. What I did is to use Google Maps Javascript API then on the request I've added the result_type=natural_feature which represents bodies of water and deserts in the address type. Adding this will return the nearest body of water in the coordinates. Javascript can be integrated on android using a Webview.
Here are my requests and responses for my two requests:
This first request is similar to getFromLocation(0,0,1)
Request:
https://maps.googleapis.com/maps/api/geocode/json?latlng=0,0&key=YOUR_API_KEY
Response:
{
"results" : [],
"status" : "ZERO_RESULTS"
}
For this next request which uses natural_feature.
Request:
https://maps.googleapis.com/maps/api/geocode/json?latlng=0,0&result_type=natural_feature&key=YOUR_API_KEY
Response:
{
"results" : [
{
"address_components" : [
{
"long_name" : "Atlantic Ocean",
"short_name" : "Atlantic Ocean",
"types" : [ "natural_feature", "establishment" ]
}
],
"formatted_address" : "Atlantic Ocean",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 68.6187515,
"lng" : 20
},
"southwest" : {
"lat" : -83.0204773,
"lng" : -83.21609509999999
}
},
"location" : {
"lat" : -14.5994134,
"lng" : -28.6731465
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 68.6187515,
"lng" : 20.0000001
},
"southwest" : {
"lat" : -83.0204773,
"lng" : -83.21609509999999
}
}
},
"place_id" : "ChIJ_7hu48qBWgYRT1MQ81ciNKY",
"types" : [ "natural_feature", "establishment" ]
},
{
"address_components" : [
{
"long_name" : "Equator",
"short_name" : "Equator",
"types" : []
}
],
"formatted_address" : "Equator",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 0,
"lng" : 180
},
"southwest" : {
"lat" : 0,
"lng" : -180
}
},
"location" : {
"lat" : 0,
"lng" : 0
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 0.00134898029150203,
"lng" : 180
},
"southwest" : {
"lat" : -0.00134898029150203,
"lng" : -180
}
}
},
"place_id" : "ChIJ9f-dgJ14AHARMp45pd8HMhs",
"types" : []
},
{
"address_components" : [
{
"long_name" : "Virgo",
"short_name" : "Virgo",
"types" : []
}
],
"formatted_address" : "Virgo",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 14.3954258,
"lng" : 47.853012
},
"southwest" : {
"lat" : -22.9842321,
"lng" : -5.6577015
}
},
"location" : {
"lat" : -4.294403099999999,
"lng" : 21.0976553
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 14.3954258,
"lng" : 47.853012
},
"southwest" : {
"lat" : -22.9842321,
"lng" : -5.6577015
}
}
},
"place_id" : "ChIJ3dT5sNUyHxoRJjQnMK1jABU",
"types" : []
}
],
"status" : "OK"
}
I want to do an android app that searchs (in Google Maps or another maps service) a walking route between two points and starts the navigation, but instead of showing the map I want to show a big arrow with the direction. Can this be done?
I have experience in java but not in Android development, currently I'm doing a course on Android development, and I need to know if this can be done if I have to reestructure my app or the requeriments.
You actually want to use GooglePlacesAPI instead of Google Maps:
https://developers.google.com/places/
This allows you to format a HTML address such as:
https://maps.googleapis.com/maps/api/directions/json?key=APIKEY&origin=42.2912,-83.7161&destination=42.293932,-83.715527&mode=walking&departure_time=now
And then will return a JSON string of something like this:
{
"routes" : [
{
"bounds" : {
"northeast" : {
"lat" : 42.2939666,
"lng" : -83.7155274
},
"southwest" : {
"lat" : 42.29159749999999,
"lng" : -83.7162498
}
},
"copyrights" : "Map data ©2015 Google",
"legs" : [
{
"distance" : {
"text" : "0.2 mi",
"value" : 322
},
"duration" : {
"text" : "5 mins",
"value" : 290
},
"end_address" : "University of Michigan - North Campus, 2086-2180 Hayward Street, Ann Arbor, MI 48109, USA",
"end_location" : {
"lat" : 42.2939666,
"lng" : -83.7155274
},
"start_address" : "University of Michigan - North Campus, 1230 Murfin Avenue, Ann Arbor, MI 48109, USA",
"start_location" : {
"lat" : 42.29159749999999,
"lng" : -83.7162498
},
"steps" : [
{
"distance" : {
"text" : "0.1 mi",
"value" : 234
},
"duration" : {
"text" : "4 mins",
"value" : 217
},
"end_location" : {
"lat" : 42.2935727,
"lng" : -83.7158445
},
"html_instructions" : "Head \u003cb\u003enortheast\u003c/b\u003e",
"polyline" : {
"points" : "oacaGpy}}N_AqAw#CgAEs#?MDMDs##eAC"
},
"start_location" : {
"lat" : 42.29159749999999,
"lng" : -83.7162498
},
"travel_mode" : "WALKING"
},
{
"distance" : {
"text" : "30 ft",
"value" : 9
},
"duration" : {
"text" : "1 min",
"value" : 10
},
"end_location" : {
"lat" : 42.2935718,
"lng" : -83.7159588
},
"html_instructions" : "Turn \u003cb\u003eleft\u003c/b\u003e toward \u003cb\u003eHayward St\u003c/b\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "ymcaG~v}}N?V"
},
"start_location" : {
"lat" : 42.2935727,
"lng" : -83.7158445
},
"travel_mode" : "WALKING"
},
{
"distance" : {
"text" : "141 ft",
"value" : 43
},
"duration" : {
"text" : "1 min",
"value" : 38
},
"end_location" : {
"lat" : 42.2939604,
"lng" : -83.7159652
},
"html_instructions" : "Turn \u003cb\u003eright\u003c/b\u003e toward \u003cb\u003eHayward St\u003c/b\u003e",
"maneuver" : "turn-right",
"polyline" : {
"points" : "ymcaGvw}}NmA#"
},
"start_location" : {
"lat" : 42.2935718,
"lng" : -83.7159588
},
"travel_mode" : "WALKING"
},
{
"distance" : {
"text" : "118 ft",
"value" : 36
},
"duration" : {
"text" : "1 min",
"value" : 25
},
"end_location" : {
"lat" : 42.2939666,
"lng" : -83.7155274
},
"html_instructions" : "Turn \u003cb\u003eright\u003c/b\u003e onto \u003cb\u003eHayward St\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003eDestination will be on the right\u003c/div\u003e",
"maneuver" : "turn-right",
"polyline" : {
"points" : "gpcaGxw}}NAgA?O"
},
"start_location" : {
"lat" : 42.2939604,
"lng" : -83.7159652
},
"travel_mode" : "WALKING"
}
],
"via_waypoint" : []
}
],
"overview_polyline" : {
"points" : "oacaGpy}}N_AqA_CIs#?MDMDs##eAC?VmA#AgA?O"
},
"summary" : "Hayward St",
"warnings" : [
"Walking directions are in beta. Use caution – This route may be missing sidewalks or pedestrian paths."
],
"waypoint_order" : []
}
],
"status" : "OK"
}
At that point, do whatever you want with it (AKA combine it with the accelerometer and GPS) to do any custom images on your screen
{
"TABLE":[
{
"ROW":[
{
"COL":[
{
"DATA":"< OutBoundSMS PhoneId='3' PhoneNo='1111111111' MessageText='OutBound SMS Application Test' />"
}
]
}
]
}
]
}
How to parse json array like this format?
I am getting this error while parsing: "cannot be converted to json object".
Parse Current Json String as:
JSONObject json=new JSONObject("Your Json String");
JSONArray jsonarray = json.getJSONArray("TABLE");
for(int i=0;i<jsonarray.length();i++){
JSONObject jsonnew=jsonarray.getJSONObject(i);
JSONArray jsonarrayROW = jsonnew.getJSONArray("ROW");
for(int j=0;j<jsonarrayROW.length();j++){
JSONObject jsonnewtwo=jsonarrayROW.getJSONObject(j);
JSONArray jsonarrayCOL = jsonnewtwo.getJSONArray("COL");
for(int k=0;k<jsonarrayCOL.length();k++){
JSONObject jsonnewthree=jsonarrayCOL.getJSONObject(k);
//get DATA here
String str_data=jsonnewthree.getString("DATA");
}
}
}
see here
String jsonStr = '{"menu": {' +
'"id": "file",' +
'"value": "File",' +
'"popup": {' +
'"menuitem": [' +
'{"value": "New", "onclick": "CreateNewDoc()"},' +
'{"value": "Open", "onclick": "OpenDoc()"},' +
'{"value": "Close", "onclick": "CloseDoc()"}' +
']' +
'}' +
'}}';
here see good example JSON PARSING
Its Working parse json data array inside array
http://maps.googleapis.com/maps/api/directions/json?origin=28.4759618,77.3140897&destination=28.3936072,77.3172154&sensor=false&mode=driving&alternatives=true
{
"geocoded_waypoints" : [
{
"geocoder_status" : "OK",
"place_id" : "ChIJzfXobhTnDDkRJQ2M4AEkun8",
"types" : [ "street_address" ]
},
{
"geocoder_status" : "OK",
"place_id" : "ChIJrz2dDk_cDDkRmnC23K0BpD4",
"types" : [ "street_address" ]
}
],
"routes" : [
{
"bounds" : {
"northeast" : {
"lat" : 28.4808871,
"lng" : 77.3195229
},
"southwest" : {
"lat" : 28.3932808,
"lng" : 77.30536649999999
}
},
"copyrights" : "Map data ©2017 Google",
"legs" : [
{
"distance" : {
"text" : "11.9 km",
"value" : 11902
},
"duration" : {
"text" : "22 mins",
"value" : 1313
},
"end_address" : "384, Sector-16, Sector 15A, Faridabad, Haryana 121007, India",
"end_location" : {
"lat" : 28.3936165,
"lng" : 77.31753990000001
},
"start_address" : "A-105, Ashoka Enclave Part II, Sector 37, Faridabad, Haryana 121003, India",
"start_location" : {
"lat" : 28.4759614,
"lng" : 77.3139839
},
"steps" : [
{
"distance" : {
"text" : "14 m",
"value" : 14
},
"duration" : {
"text" : "1 min",
"value" : 3
},
"end_location" : {
"lat" : 28.4760899,
"lng" : 77.31398329999999
},
"html_instructions" : "Head \u003cb\u003enorth\u003c/b\u003e",
"polyline" : {
"points" : "wuxlDkk{vMY?"
},
"start_location" : {
"lat" : 28.4759614,
"lng" : 77.3139839
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0.4 km",
"value" : 440
},
"duration" : {
"text" : "2 mins",
"value" : 116
},
"end_location" : {
"lat" : 28.4766301,
"lng" : 77.3097228
},
"html_instructions" : "Turn \u003cb\u003eleft\u003c/b\u003e toward \u003cb\u003eOld Sher Shah Suri Road\u003c/b\u003e/\u003cb\u003eSarai Khawaja Rd\u003c/b\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "qvxlDkk{vMApB?Z?jB?bACvDAx#?T#v#?#Dx#?H?FADABCBw#bAQRY`#"
},
"start_location" : {
"lat" : 28.4760899,
"lng" : 77.31398329999999
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0.5 km",
"value" : 503
},
"duration" : {
"text" : "1 min",
"value" : 81
},
"end_location" : {
"lat" : 28.4808871,
"lng" : 77.30797579999999
},
"html_instructions" : "Slight \u003cb\u003eright\u003c/b\u003e onto \u003cb\u003eOld Sher Shah Suri Road\u003c/b\u003e/\u003cb\u003eSarai Khawaja Rd\u003c/b\u003e",
"maneuver" : "turn-slight-right",
"polyline" : {
"points" : "}yxlDwpzvMIDiF|AcBh#{Bp#eGhByBp#"
},
"start_location" : {
"lat" : 28.4766301,
"lng" : 77.3097228
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0.3 km",
"value" : 255
},
"duration" : {
"text" : "1 min",
"value" : 50
},
"end_location" : {
"lat" : 28.4808239,
"lng" : 77.30536649999999
},
"html_instructions" : "Turn \u003cb\u003eleft\u003c/b\u003e onto \u003cb\u003eMain Rd\u003c/b\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "qtylD{ezvMHnEBxH"
},
"start_location" : {
"lat" : 28.4808871,
"lng" : 77.30797579999999
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "1.0 km",
"value" : 1013
},
"duration" : {
"text" : "2 mins",
"value" : 125
},
"end_location" : {
"lat" : 28.4717998,
"lng" : 77.30594619999999
},
"html_instructions" : "Turn \u003cb\u003eleft\u003c/b\u003e onto \u003cb\u003eNH19\u003c/b\u003e/\u003cb\u003eNH44\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003ePass by Hotel Saffron Kiran (on the left in 1.0 km)\u003c/div\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "ctylDquyvMhA?^An#?lAEfAGrEQzBMH?DALEJGzCw#TC`#C^AV?P?T#rALL?v#B\\?VAz#CjB#h#?X?fBG~#B^NrCKTA"
},
"start_location" : {
"lat" : 28.4808239,
"lng" : 77.30536649999999
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "7.5 km",
"value" : 7549
},
"duration" : {
"text" : "10 mins",
"value" : 624
},
"end_location" : {
"lat" : 28.4041209,
"lng" : 77.3116127
},
"html_instructions" : "Keep \u003cb\u003eright\u003c/b\u003e to stay on \u003cb\u003eNH19\u003c/b\u003e/\u003cb\u003eNH44\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003ePass by Bank Of India (on the left in 2.4 km)\u003c/div\u003e",
"maneuver" : "keep-right",
"polyline" : {
"points" : "w{wlDeyyvM|HU`DMrAEnQu#jASVCXEpGUfDM`BGl#ED?z#CrAGpAEdBI^AfF[~DSvLa#xJ_#lFSvEQlHQlIa#zHUnIa#~FWbBItBGfDIbDMrAP|DMnCMxBEl#?`BGtBMhAG`H[d#AnEQZAxBGbBGfFSxBIpBI`GSfEOlCIVATAh#Ch#AzFWtQu#rHWd#C~J_#`FQl#A`#Ct#AnAE`#Cr#EhCI^A\\Al#El#Ch#ApCOxBI\\AnDOvBG|BIdESzGU|DMvAG`#CdDOnAE~CIf#ElAClDM"
},
"start_location" : {
"lat" : 28.4717998,
"lng" : 77.30594619999999
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "11 m",
"value" : 11
},
"duration" : {
"text" : "1 min",
"value" : 4
},
"end_location" : {
"lat" : 28.404129,
"lng" : 77.3117281
},
"html_instructions" : "Turn \u003cb\u003eleft\u003c/b\u003e onto \u003cb\u003eGovernment College Rd\u003c/b\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "wtjlDq|zvMAW"
},
"start_location" : {
"lat" : 28.4041209,
"lng" : 77.3116127
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0.3 km",
"value" : 274
},
"duration" : {
"text" : "1 min",
"value" : 31
},
"end_location" : {
"lat" : 28.4016677,
"lng" : 77.31193089999999
},
"html_instructions" : "Turn \u003cb\u003eright\u003c/b\u003e toward \u003cb\u003eLal Bahadur Shastri Marg\u003c/b\u003e",
"maneuver" : "turn-right",
"polyline" : {
"points" : "ytjlDi}zvMz#CzBMz#Ah#ClEO"
},
"start_location" : {
"lat" : 28.404129,
"lng" : 77.3117281
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0.7 km",
"value" : 677
},
"duration" : {
"text" : "2 mins",
"value" : 100
},
"end_location" : {
"lat" : 28.4018048,
"lng" : 77.318851
},
"html_instructions" : "Turn \u003cb\u003eleft\u003c/b\u003e onto \u003cb\u003eLal Bahadur Shastri Marg\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003ePass by Sun Flag Hospital & Research Centre (on the left in 650 m)\u003c/div\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "mejlDq~zvMA]?_A?sD?gD?yC?_F?q#EiDIwCCcBC{A"
},
"start_location" : {
"lat" : 28.4016677,
"lng" : 77.31193089999999
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0.9 km",
"value" : 936
},
"duration" : {
"text" : "2 mins",
"value" : 126
},
"end_location" : {
"lat" : 28.3934097,
"lng" : 77.3195229
},
"html_instructions" : "Turn \u003cb\u003eright\u003c/b\u003e at \u003cb\u003eSector 16 Rd\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003ePass by Gymkhana Club - I (on the right)\u003c/div\u003e",
"maneuver" : "turn-right",
"polyline" : {
"points" : "gfjlDyi|vMnAGrNg#nBGtBInIUlDKdJa#"
},
"start_location" : {
"lat" : 28.4018048,
"lng" : 77.318851
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0.2 km",
"value" : 193
},
"duration" : {
"text" : "1 min",
"value" : 41
},
"end_location" : {
"lat" : 28.3932808,
"lng" : 77.3175523
},
"html_instructions" : "Turn \u003cb\u003eright\u003c/b\u003e",
"maneuver" : "turn-right",
"polyline" : {
"points" : "yqhlD_n|vMPrE#nADdB"
},
"start_location" : {
"lat" : 28.3934097,
"lng" : 77.3195229
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "37 m",
"value" : 37
},
"duration" : {
"text" : "1 min",
"value" : 12
},
"end_location" : {
"lat" : 28.3936165,
"lng" : 77.31753990000001
},
"html_instructions" : "Turn \u003cb\u003eright\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003eDestination will be on the left\u003c/div\u003e",
"maneuver" : "turn-right",
"polyline" : {
"points" : "_qhlDua|vMcA#"
},
"start_location" : {
"lat" : 28.3932808,
"lng" : 77.3175523
},
"travel_mode" : "DRIVING"
}
],
"traffic_speed_entry" : [],
"via_waypoint" : []
}
],
"overview_polyline" : {
"points" : "wuxlDkk{vMY?ApB?fCEjIF|BGTiAvAY`#IDmIfCaKzCyBp#HnEBxHhA?nAAtCM~Ia#XMpD{#`AEh#?hBNdAB|ECbA?fBG~#B^NrCKrIWtFSnQu#jASp#IxLc#pEQjHYfLo#pXaAdMe#lHQlIa#zHUnIa#bJa#|GQbDMrAPlI[fDEvEUjJc#jK]fd#_BdJ_#h[mAdLc#fJYnHYlNk#jRu#rQo#tFUfEOzFQAWz#CvDOvFSAyL?yJE{EM{FC{AnAGbRo#dM_#lDKdJa#RbHDdBcA#"
},
"summary" : "NH19/NH44",
"warnings" : [],
"waypoint_order" : []
}
],
"status" : "OK"
}
Handle
import android.app.Dialog;
import android.app.ProgressDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class MainActivity extends AppCompatActivity {
private Dialog mDialog;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
callApiArrayInsideArray();
}
private void callApiArrayInsideArray() {
JSONObject jsonObject = new JSONObject();
// TODO Send parameter using this in volley apis
/*try {
jsonObject.put("UserId", "abc");
} catch (JSONException e) {
e.printStackTrace();
}*/
// String url = Constants.GetData;
String url = "http://maps.googleapis.com/maps/api/directions/json?origin=28.4759618,77.3140897&destination=28.3936072,77.3172154&sensor=false&mode=driving&alternatives=true";
mDialog = ProgressDialog.show(MainActivity.this, "", "Please wait", true);
mDialog.setCancelable(false);
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url,
jsonObject, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
Log.i("tag", "Volley response: " + response.toString());
if (mDialog != null) {
mDialog.dismiss();
}
// TODO when Success Response then set parse data in list view
parseResponse(response);
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
if (mDialog != null) {
mDialog.dismiss();
}
Log.i("tag", "Volley error: " + error.getMessage());
}
});
Volley.newRequestQueue(this).add(jsonObjectRequest);
}
private void parseResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONArray("routes");
Log.e("MainActivity", "jsonArray --> " + jsonArray.toString(2));
if (jsonArray != null)
{
for (int i = 0; i < jsonArray.length(); i++)
{
JSONObject jsonnew = jsonArray.getJSONObject(i);
JSONArray jsonarrayROW = jsonnew.getJSONArray("legs");
for (int j = 0; j < jsonarrayROW.length(); j++)
{
JSONObject jsonnewtwo = jsonarrayROW.getJSONObject(j);
JSONArray jsonarrayCOL = jsonnewtwo.getJSONArray("steps");
for (int k = 0; k < jsonarrayCOL.length(); k++)
{
JSONObject jsonnewthree = jsonarrayCOL.getJSONObject(k);
String str_data = jsonnewthree.getString("html_instructions");
Log.e("Keshav", "html_instructions -> " + str_data);
}
}
Log.e("Keshav", "GeoEvent List->");
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
I am trying to draw a route on google maps in android.
For that I use the google direction api to get the route points http://code.google.com/intl/de-DE/apis/maps/documentation/directions/
Now I would like to know how to get the directions arrow (like: turn left,...)
from the json response of this api.
A response look like:
{
"routes" : [
{
"bounds" : {
"northeast" : {
"lat" : 48.306950,
"lng" : 14.304310
},
"southwest" : {
"lat" : 48.163440,
"lng" : 14.033580
}
},
"copyrights" : "Map data ©2012 GeoBasis-DE/BKG (©2009), Google",
"legs" : [
{
"distance" : {
"text" : "34.6 km",
"value" : 34554
},
"duration" : {
"text" : "31 mins",
"value" : 1866
},
"end_address" : "Linz, Austria",
"end_location" : {
"lat" : 48.306950,
"lng" : 14.285860
},
"start_address" : "Wels, Austria",
"start_location" : {
"lat" : 48.16545000000001,
"lng" : 14.036620
},
"steps" : [
{
"distance" : {
"text" : "0.3 km",
"value" : 252
},
"duration" : {
"text" : "1 min",
"value" : 28
},
"end_location" : {
"lat" : 48.164110,
"lng" : 14.033890
},
"html_instructions" : "Head \u003cb\u003esouthwest\u003c/b\u003e on \u003cb\u003eHans-Sachs-Straße\u003c/b\u003e toward \u003cb\u003eGemeindestr.\u003c/b\u003e",
"polyline" : {
"points" : "ai~dH{ottAHHHNN`#jBjFzBxF"
},
"start_location" : {
"lat" : 48.16545000000001,
"lng" : 14.036620
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0.1 km",
"value" : 149
},
"duration" : {
"text" : "1 min",
"value" : 48
},
"end_location" : {
"lat" : 48.163440,
"lng" : 14.03470
},
"html_instructions" : "At the roundabout, take the \u003cb\u003e3rd\u003c/b\u003e exit onto \u003cb\u003eMagazinstr./B1\u003c/b\u003e",
"polyline" : {
"points" : "u`~dHy~stAEBCDAHAH#H#HDHB#B#D?DABADGBG#G?GAIAGvAkCP_#"
},
"start_location" : {
"lat" : 48.164110,
"lng" : 14.033890
},
"travel_mode" : "DRIVING"
},
.
.
.
This should be possible, because google maps: http://maps.google.com/ uses the same direction api (as far as i know) and it draws such arrows on the left side of every entry of the route description (just calculate any route to see what I mean).
I very appreciate every kind of help
Have a look at my answer. This will give you an other way get the direction instructions
using KML file
This is what I am using,
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr="+latitude_cur+","+longitude_cur+"&daddr="+latitude+","+longitude));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addCategory(Intent.CATEGORY_LAUNCHER );
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);