PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 23 → WX Informatica - Exemplo de Google Maps com Json retornando Distancia, Tempo e Rota
WX Informatica - Exemplo de Google Maps com Json retornando Distancia, Tempo e Rota
Débuté par BOLLER, 16 fév. 2018 23:14 - 5 réponses
Membre enregistré
2 867 messages
Popularité : +89 (91 votes)
Posté le 16 février 2018 - 23:14
Prezados,

Segue abaixo Exemplo de Google Maps com Json retornando Distancia, Tempo e Rota





Exemplo Usando uma tabela HFSQL

code:wl]
GLOBAL
gloLatitudeOrigem, gloLongitudeOrigem, gloLatitudeDestino, gloLongitudeDestino, grDistancia, grTempo is real

ST_GoogleMaps is Structure
sGoogleMapsName is string
sGoogleMapsValue is string
END
arrGoogle is array of 5000 ST_GoogleMaps

[/code]

Procedure GoogleMapsRotaTable(Origem, Destino, XmlJson)

//Origem = "dr goulin 1699 curitiba PR"
//Destino = "rua clavio molinari 1029 curitiba PR"

PersonalJson is Variant

XmlJsonResultado is string

IF Origem <> "" AND Destino = "" THEN
Destino = Origem
END

ok is boolean = False

IF Origem <> "" AND Destino <> ""

ChangeCharset(charsetOccidental) // SEM ACENTO

Origem = Capitalize(NoAccent(Origem))

Origem = Replace(Origem," ","+")

Destino = Capitalize(NoAccent(Destino))

Destino = Replace(Destino," ","+")

HTTPCreateForm("GoogleMaps")
HTTPAddParameter("GoogleMaps","origin", Origem)
HTTPAddParameter("GoogleMaps","destination", Destino)
HTTPAddParameter("GoogleMaps","language", "pt-BR")
HTTPAddParameter("GoogleMaps","region", "br")
HTTPAddParameter("GoogleMaps","units", "metric")

HTTPAddParameter("GoogleMaps","key","AIzaSyDbSVKYPwB1a-_vPbDzAr6LgAfIj4iW2hc") //CHAVE GOOGLE

cMyRequest is a httpRequest

IF Upper(XmlJson) = "XML"
cMyRequest..URL = "https://maps.googleapis.com/maps/api/directions/xml"
ELSE IF Upper(XmlJson) = "JSON"
cMyRequest..URL = "https://maps.googleapis.com/maps/api/directions/json"
END

cMyRequest..Method = httpGet

cMyResponse is a httpResponse = HTTPSendForm("GoogleMaps", cMyRequest)

IF cMyResponse..StatusCode <> 200 THEN // Se não funcionou

XmlJsonResultado = "Erro"

ELSE

PersonalJson = JSONToVariant(cMyResponse.Content)

HDeleteAll(GoogleMaps)

//Status
GoogleMaps.Name = "Status"
GoogleMaps.Value01 = PersonalJson.routes[1].geocoder_status
HAdd(GoogleMaps)


//NORTE
GoogleMaps.Name = "Latitude Norte"
GoogleMaps.Value01 = PersonalJson.routes[1].bounds.northeast.lat..Value
HAdd(GoogleMaps)

//NORTE
GoogleMaps.Name = "Longitude Norte"
GoogleMaps.Value01 = PersonalJson.routes[1].bounds.northeast.lng..Value
HAdd(GoogleMaps)


//SUL
GoogleMaps.Name = "Latitude Sul"
GoogleMaps.Value01 = PersonalJson.routes[1].bounds.southwest.lat..Value
HAdd(GoogleMaps)

//SUL
GoogleMaps.Name = "Longitude Sul"
GoogleMaps.Value01 = PersonalJson.routes[1].bounds.southwest.lng..Value
HAdd(GoogleMaps)


//DISTANCIA - TXT
GoogleMaps.Name = "Distancia Texto Total"
GoogleMaps.Value01 = PersonalJson.routes[1].legs[1].distance.text..Value
HAdd(GoogleMaps)

//DISTANCIA - VALUE
GoogleMaps.Name = "Distancia Valor Total"
GoogleMaps.Value01 = PersonalJson.routes[1].legs[1].distance.value..Value
grDistancia = GoogleMaps.Value01 //<------------------- DISTANCIA
HAdd(GoogleMaps)



//DURACAO - TXT
GoogleMaps.Name = "Duracao Texto Total"
GoogleMaps.Value01 = PersonalJson.routes[1].legs[1].duration.text..Value
HAdd(GoogleMaps)

//DURACAO - VALUE
GoogleMaps.Name = "Duracao Valor Total"
GoogleMaps.Value01 = PersonalJson.routes[1].legs[1].duration.value..Value
grTempo = GoogleMaps.Value01 //<------------------- TEMPO
HAdd(GoogleMaps)


//ENDERECO INICIAL
GoogleMaps.Name = "Endereço Completo Inicial"
GoogleMaps.Value01 = PersonalJson.routes[1].legs[1].start_address..Value
HAdd(GoogleMaps)


//ENDERECO INICIAL LATITUDE
GoogleMaps.Name = "Endereço Inicial Latitude"
GoogleMaps.Value01 = PersonalJson.routes[1].legs[1].start_location.lat..Value
gloLatitudeOrigem = GoogleMaps.Value01 //<------------------- LAT ORIGEM
HAdd(GoogleMaps)

//ENDERECO INICIAL LONGITUDE
GoogleMaps.Name = "Endereço Inicial Longitude"
GoogleMaps.Value01 = PersonalJson.routes[1].legs[1].start_location.lng..Value
gloLongitudeOrigem = GoogleMaps.Value01 //<------------------- LONG ORIGEM
HAdd(GoogleMaps)



//ENDERECO FINAL
GoogleMaps.Name = "Endereço Completo Final"
GoogleMaps.Value01 = PersonalJson.routes[1].legs[1].end_address..Value
HAdd(GoogleMaps)

//ENDERECO FINAL LATITUDE
GoogleMaps.Name = "Endereço Final Latitude"
GoogleMaps.Value01 = PersonalJson.routes[1].legs[1].end_location.lat..Value
gloLatitudeDestino = GoogleMaps.Value01 //<------------------- LAT DESTINO
HAdd(GoogleMaps)

//ENDERECO FINAL LONGITUDE
GoogleMaps.Name = "Endereço Final Longitude"
GoogleMaps.Value01 = PersonalJson.routes[1].legs[1].end_location.lng..Value
gloLongitudeDestino= GoogleMaps.Value01 //<------------------- LONG DESTINO
HAdd(GoogleMaps)


//Steps
i is int = 0

FOR EACH x OF PersonalJson.routes[1].legs[1].steps

i+= 1

GoogleMaps.Name = "Step ["+ i +"]"
HAdd(GoogleMaps)

GoogleMaps.Name = "Step ["+ i +"] Latitude Inicial"
GoogleMaps.Value01 = PersonalJson.routes[1].legs[1].steps[i].start_location.lat
HAdd(GoogleMaps)

GoogleMaps.Name = "Step ["+ i +"] Longitude Inicial"
GoogleMaps.Value01 = PersonalJson.routes[1].legs[1].steps[i].start_location.lng
HAdd(GoogleMaps)

GoogleMaps.Name = "Step ["+ i +"] Latitude Final"
GoogleMaps.Value01 = PersonalJson.routes[1].legs[1].steps[i].end_location.lat
HAdd(GoogleMaps)

GoogleMaps.Name = "Step ["+ i +"] Longitude Final"
GoogleMaps.Value01 = PersonalJson.routes[1].legs[1].steps[i].end_location.lng
HAdd(GoogleMaps)

GoogleMaps.Name = "Step ["+ i +"] Distancia text"
GoogleMaps.Value01 = PersonalJson.routes[1].legs[1].steps[i].distance.text
HAdd(GoogleMaps)

GoogleMaps.Name = "Step ["+ i +"] Distancia value"
GoogleMaps.Value01 = PersonalJson.routes[1].legs[1].steps[i].distance.value
HAdd(GoogleMaps)

GoogleMaps.Name = "Step ["+ i +"] Duracao text"
GoogleMaps.Value01 = PersonalJson.routes[1].legs[1].steps[i].duration.text
HAdd(GoogleMaps)

GoogleMaps.Name = "Step ["+ i +"] Duracao value"
GoogleMaps.Value01 = PersonalJson.routes[1].legs[1].steps[i].duration.value
HAdd(GoogleMaps)

GoogleMaps.Name = "Step ["+ i +"] Instruções de Voz"
GoogleMaps.Value01 = PersonalJson.routes[1].legs[1].steps[i].html_instructions
HAdd(GoogleMaps)

GoogleMaps.Name = "Step ["+ i +"] Points Polyline Endcode Google"
GoogleMaps.Value01 = PersonalJson.routes[1].legs[1].steps[i].polyline.points
HAdd(GoogleMaps)

GoogleMaps.Name = "Step ["+ i +"] Travel Mode"
GoogleMaps.Value01 = PersonalJson.routes[1].legs[1].steps[i].travel_mode
HAdd(GoogleMaps)

END

END

XmlJsonResultado = "OK"

ELSE

XmlJsonResultado = "Erro"

END

RESULT(XmlJsonResultado)


Resultado Json apos o Httprequest




Resultado após a importação do json para Hfsql









CODIGO DO BOTAO
GoogleMapsRotaTable(EDT_Origem,EDT_Destino,"JSON")

POrigem is geoPosition
POrigem..Latitude = gloLatitudeOrigem
POrigem..Longitude = gloLongitudeOrigem

MarkerOrigem is Marker
MarkerOrigem..Position = POrigem
MarkerOrigem..Name = "Origem"
MarkerOrigem..Description = "Origem"
MapAddMarker(MAP_GoogleMaps,MarkerOrigem)

PDestino is geoPosition
PDestino..Latitude = gloLatitudeDestino
PDestino..Longitude = gloLongitudeDestino

MarkerDestino is Marker
MarkerDestino..Position = PDestino
MarkerDestino..Name = "Destino"
MarkerDestino..Description = "Destino"
MapAddMarker(MAP_GoogleMaps,MarkerDestino)

MapAddItinerary(MAP_GoogleMaps,[POrigem,PDestino],itineraryCar)

BTN_DISTANCIA..Text = "Distancia: "+grDistancia+" km"

BTN_TEMPO..Text = "Tempo: "+grTempo+" min"


RESULTADO FINAL





--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 99949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/
Message modifié, 17 février 2018 - 00:23
Membre enregistré
2 867 messages
Popularité : +89 (91 votes)
Posté le 16 février 2018 - 23:22
{<10> "geocoded_waypoints" : [<10> {<10> "geocoder_status" : "OK",<10> "partial_match" : true,<10> "place_id" : "ChIJMVMc2jTk3JQR_KS3mkr2lMY",<10> "types" : [ "street_address" ]<10> },<10> {<10> "geocoder_status" : "OK",<10> "place_id" : "Ek5SLiBDbMOhdmlvIE1vbGluYXJpLCAxMDI5IC0gQ2Fww6NvIGRhIEltYnVpYSwgQ3VyaXRpYmEgLSBQUiwgODI4MTAtMjEwLCBCcmFzaWw",<10> "types" : [ "street_address" ]<10> }<10> ],<10> "routes" : [<10> {<10> "bounds" : {<10> "northeast" : {<10> "lat" : -25.4177243,<10> "lng" : -49.209473<10> },<10> "southwest" : {<10> "lat" : -25.4404742,<10> "lng" : -49.2442012<10> }<10> },<10> "copyrights" : "Dados cartográficos ©2018 Google",<10> "legs" : [<10> {<10> "distance" : {<10> "text" : "6,2 km",<10> "value" : 6222<10> },<10> "duration" : {<10> "text" : "13 minutos",<10> "value" : 802<10> },<10> "end_address" : "R. Clávio Molinari, 1029 - Capão da Imbuia, Curitiba - PR, 82810-210, Brasil",<10> "end_location" : {<10> "lat" : -25.4404742,<10> "lng" : -49.209473<10> },<10> "start_address" : "R. Dr. Goulin, 1699 - Alto da Glória, Curitiba - PR, 80040-280, Brasil",<10> "start_location" : {<10> "lat" : -25.4189803,<10> "lng" : -49.2442012<10> },<10> "steps" : [<10> {<10> "distance" : {<10> "text" : "15 m",<10> "value" : 15<10> },<10> "duration" : {<10> "text" : "1 min",<10> "value" : 3<10> },<10> "end_location" : {<10> "lat" : -25.4189929,<10> "lng" : -49.2440539<10> },<10> "html_instructions" : "Siga na direção \u003cb\u003eleste\u003c/b\u003e na \u003cb\u003eR. Dr. Goulin\u003c/b\u003e em direção Ã<SPC> \u003cb\u003eRua Flávio Dallegrave\u003c/b\u003e",<10> "polyline" : {<10> "points" : "rsczCf_qkH@]"<10> },<10> "start_location" : {<10> "lat" : -25.4189803,<10> "lng" : -49.2442012<10> },<10> "travel_mode" : "DRIVING"<10> },<10> {<10> "distance" : {<10> "text" : "0,1 km",<10> "value" : 144<10> },<10> "duration" : {<10> "text" : "1 min",<10> "value" : 47<10> },<10> "end_location" : {<10> "lat" : -25.4177243,<10> "lng" : -49.2437741<10> },<10> "html_instructions" : "Vire Ã<SPC> \u003cb\u003eesquerda\u003c/b\u003e na \u003cb\u003eR. Pres. Rodrigo Otávio\u003c/b\u003e",<10> "maneuver" : "turn-left",<10> "polyline" : {<10> "points" : "tsczCh~pkHUGa@Ka@G[Eq@IuAK"<10> },<10> "start_location" : {<10> "lat" : -25.4189929,<10> "lng" : -49.2440539<10> },<10> "travel_mode" : "DRIVING"<10> },<10> {<10> "distance" : {<10> "text" : "0,3 km",<10> "value" : 266<10> },<10> "duration" : {<10> "text" : "1 min",<10> "value" : 54<10> },<10> "end_location" : {<10> "lat" : -25.4179433,<10> "lng" : -49.2411403<10> },<10> "html_instructions" : "Vire Ã<SPC> \u003cb\u003edireita\u003c/b\u003e na 1ª rua transversal para \u003cb\u003eR. Augusto Stresser\u003c/b\u003e",<10> "maneuver" : "turn-right",<10> "polyline" : {<10> "points" : "vkczCp|pkHD_@@[@Y@S@U@e@@K@o@@UDy@@a@HsB@a@@c@"<10> },<10> "start_location" : {<10> "lat" : -25.4177243,<10> "lng" : -49.2437741<10> },<10> "travel_mode" : "DRIVING"<10> },<10> {<10> "distance" : {<10> "text" : "1,3 km",<10> "value" : 1288<10> },<10> "duration" : {<10> "text" : "2 minutos",<10> "value" : 128<10> },<10> "end_location" : {<10> "lat" : -25.4282871,<10> "lng" : -49.2414666<10> },<10> "html_instructions" : "Vire Ã<SPC> \u003cb\u003edireita\u003c/b\u003e na \u003cb\u003eAv. N. Sra. da Luz\u003c/b\u003e",<10> "maneuver" : "turn-right",<10> "polyline" : {<10> "points" : "bmczCblpkHnAq@RKb@UHEr@_@jAm@`Ag@`@QPIf@QJEHAJAHAPA^@NBPD@@b@VvCrBZX`D|Bf@^ZV`Av@TNvA|@h@VVJXHXDfANV@T?T?VCTC`@Eb@IfAQfAS^M|Bm@ZKVKJGXK@AJENIj@Ul@Y"<10> },<10> "start_location" : {<10> "lat" : -25.4179433,<10> "lng" : -49.2411403<10> },<10> "travel_mode" : "DRIVING"<10> },<10> {<10> "distance" : {<10> "text" : "0,1 km",<10> "value" : 141<10> },<10> "duration" : {<10> "text" : "1 min",<10> "value" : 28<10> },<10> "end_location" : {<10> "lat" : -25.4276542,<10> "lng" : -49.2405717<10> },<10> "html_instructions" : "Curva acentuada Ã<SPC> \u003cb\u003eesquerda\u003c/b\u003e na rampa de acesso a \u003cb\u003eAv. Victor Ferreira do Amaral\u003c/b\u003e",<10> "polyline" : {<10> "points" : "xmezCdnpkHJSBGBG@C@E?C?A?C?CAECCWGWEKCKEIGGECCEEGGEIGKIOMO"<10> },<10> "start_location" : {<10> "lat" : -25.4282871,<10> "lng" : -49.2414666<10> },<10> "travel_mode" : "DRIVING"<10> },<10> {<10> "distance" : {<10> "text" : "2,6 km",<10> "value" : 2553<10> },<10> "duration" : {<10> "text" : "4 minutos",<10> "value" : 256<10> },<10> "end_location" : {<10> "lat" : -25.4300114,<10> "lng" : -49.2153913<10> },<10> "html_instructions" : "Continue para \u003cb\u003eAv. Victor Ferreira do Amaral\u003c/b\u003e",<10> "polyline" : {<10> "points" : "xiezCphpkHEICKAAMc@I_@G]CSAQAY@c@NmCJkC?WZ_GF_AR_DR}CJ}CFiABo@BYBUZyE@[VyDH_BJ_BFmAHkA@cABi@B]Bc@L{BFeADgAFiAXoFN_ET}DDw@NyCHaBHkAHq@Bm@Fo@Ai@B_@f@uJP_DJkBHeBNoCNgC"<10> },<10> "start_location" : {<10> "lat" : -25.4276542,<10> "lng" : -49.2405717<10> },<10> "travel_mode" : "DRIVING"<10> },<10> {<10> "distance" : {<10> "text" : "0,8 km",<10> "value" : 784<10> },<10> "duration" : {<10> "text" : "2 minutos",<10> "value" : 98<10> },<10> "end_location" : {<10> "lat" : -25.4363978,<10> "lng" : -49.2186964<10> },<10> "html_instructions" : "Vire Ã<SPC> \u003cb\u003edireita\u003c/b\u003e na \u003cb\u003eR. Prof. Nivaldo Braga\u003c/b\u003e (placas para \u003cb\u003eUnibrasil\u003c/b\u003e/\u003cb\u003eCemitério Vertical\u003c/b\u003e)",<10> "maneuver" : "turn-right",<10> "polyline" : {<10> "points" : "pxezCdkkkHlBp@`A\\hA`@hAd@`@P^N`A`@h@Rl@Vn@Xp@Xr@Zn@Xn@Xp@Zn@XbBt@`Bt@l@Xl@Zp@Vp@X"<10> },<10> "start_location" : {<10> "lat" : -25.4300114,<10> "lng" : -49.2153913<10> },<10> "travel_mode" : "DRIVING"<10> },<10> {<10> "distance" : {<10> "text" : "1,0 km",<10> "value" : 1031<10> },<10> "duration" : {<10> "text" : "3 minutos",<10> "value" : 188<10> },<10> "end_location" : {<10> "lat" : -25.4404742,<10> "lng" : -49.209473<10> },<10> "html_instructions" : "Vire Ã<SPC> \u003cb\u003eesquerda\u003c/b\u003e na \u003cb\u003eR. Clávio Molinari\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003eO destino estará Ã<SPC> esquerda\u003c/div\u003e",<10> "maneuver" : "turn-left",<10> "polyline" : {<10> "points" : "n`gzCz_lkHdAaDbAaDd@mAd@mA`@sAb@sA`@mA`@mAd@oAd@oAjCcIfAaDfAaDdAaD^gA"<10> },<10> "start_location" : {<10> "lat" : -25.4363978,<10> "lng" : -49.2186964<10> },<10> "travel_mode" : "DRIVING"<10> }<10> ],<10> "traffic_speed_entry" : [],<10> "via_waypoint" : []<10> }<10> ],<10> "overview_polyline" : {<10> "points" : "rsczCf_qkH@]UGcASmAOuAKD_@Bu@Bi@FwBRqF@c@nAq@v@a@jE{Br@[r@Wp@Gn@DRFzDjC|DvCzC~BvA|@h@Vp@T`BTl@@l@Cv@IjB[fBa@xCy@b@Sv@]xAo@N[FUAO[Kc@Ia@W[c@W_@IUa@cBEe@?}@v@qPZ_FR}CJ}CJyBFo@~@oORmDHkA@cAFgAP_Dn@gMd@}JTqERmDL_BFo@Ai@B_@nAgV^wGnDnArCfA`A`@hEfBdEhBfH`DzAt@bBp@hCcIjA{ChCcIjA_DrEeNlDkK"<10> },<10> "summary" : "Av. Victor Ferreira do Amaral",<10> "warnings" : [],<10> "waypoint_order" : []<10> }<10> ],<10> "status" : "OK"<10>}<10>


--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 99949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/
Membre enregistré
2 867 messages
Popularité : +89 (91 votes)
Posté le 17 février 2018 - 00:38
Exemplo usando Array em vez de Tabela

CODIGO GLOBAL
//Vars Global
GLOBAL
gsUser, gsPassword is string

gloLatitudeOrigem, gloLongitudeOrigem, gloLatitudeDestino, gloLongitudeDestino, grDistancia, grTempo is real

ST_GoogleMaps is structure
sGoogleMapsName is string
sGoogleMapsValue is string
END
arrGoogle is array of 5000 ST_GoogleMaps


CODIGO DO BOTAO
//GoogleMapsRotaTable(EDT_Origem,EDT_Destino,"JSON")

GoogleMapsRotaArray(EDT_Origem,EDT_Destino,"JSON")

MapDeleteMarker(MAP_GoogleMaps)

MapDeleteAll(MAP_GoogleMaps)

POrigem is geoPosition
POrigem..Latitude = gloLatitudeOrigem
POrigem..Longitude = gloLongitudeOrigem

MarkerOrigem is Marker
MarkerOrigem..Position = POrigem
MarkerOrigem..Name = "Origem"
MarkerOrigem..Description = "Origem"
MapAddMarker(MAP_GoogleMaps,MarkerOrigem)

PDestino is geoPosition
PDestino..Latitude = gloLatitudeDestino
PDestino..Longitude = gloLongitudeDestino

MarkerDestino is Marker
MarkerDestino..Position = PDestino
MarkerDestino..Name = "Destino"
MarkerDestino..Description = "Destino"
MapAddMarker(MAP_GoogleMaps,MarkerDestino)

MapAddItinerary(MAP_GoogleMaps,[POrigem,PDestino],itineraryCar)

BTN_DISTANCIA..Text = "Distancia: "+grDistancia+" km"

BTN_TEMPO..Text = "Tempo: "+grTempo+" min"



PROCEDURE COM ARRAY

Procedure GoogleMapsRotaArray(Origem, Destino, XmlJson)

//Origem = "dr goulin 1699 curitiba PR"
//Destino = "rua clavio molinari 1029 curitiba PR"

PersonalJson is Variant

XmlJsonResultado is string

IF Origem <> "" AND Destino = "" THEN
Destino = Origem
END

ok is boolean = False

IF Origem <> "" AND Destino <> ""

ChangeCharset(charsetOccidental) // SEM ACENTO

Origem = Capitalize(NoAccent(Origem))

Origem = Replace(Origem," ","+")

Destino = Capitalize(NoAccent(Destino))

Destino = Replace(Destino," ","+")

HTTPCreateForm("GoogleMaps")
HTTPAddParameter("GoogleMaps","origin", Origem)
HTTPAddParameter("GoogleMaps","destination", Destino)
HTTPAddParameter("GoogleMaps","language", "pt-BR")
HTTPAddParameter("GoogleMaps","region", "br")
HTTPAddParameter("GoogleMaps","units", "metric")

HTTPAddParameter("GoogleMaps","key","AIzaSyDbSVKYPwB1a-_vPbDzAr6LgAfIj4iW2hc") //CHAVE GOOGLE

cMyRequest is a httpRequest

IF Upper(XmlJson) = "XML"
cMyRequest..URL = "https://maps.googleapis.com/maps/api/directions/xml"
ELSE IF Upper(XmlJson) = "JSON"
cMyRequest..URL = "https://maps.googleapis.com/maps/api/directions/json"
END

cMyRequest..Method = httpGet

cMyResponse is a httpResponse = HTTPSendForm("GoogleMaps", cMyRequest)

IF cMyResponse..StatusCode <> 200 THEN // Se não funcionou

XmlJsonResultado = "Erro"

ELSE

PersonalJson = JSONToVariant(cMyResponse.Content)

index is int = 0

//Status
index++
arrGoogle[index].sGoogleMapsName = "Status"
arrGoogle[index].sGoogleMapsValue = "OK"



//NORTE
index++
arrGoogle[index].sGoogleMapsName = "Latitude Norte"
arrGoogle[index].sGoogleMapsValue = PersonalJson.routes[1].bounds.northeast.lat..Value

//NORTE
index++
arrGoogle[index].sGoogleMapsName = "Longitude Norte"
arrGoogle[index].sGoogleMapsValue = PersonalJson.routes[1].bounds.northeast.lng..Value



//SUL
index++
arrGoogle[index].sGoogleMapsName = "Latitude Sul"
arrGoogle[index].sGoogleMapsValue = PersonalJson.routes[1].bounds.southwest.lat..Value


//SUL
index++
arrGoogle[index].sGoogleMapsName = "Longitude Sul"
arrGoogle[index].sGoogleMapsValue = PersonalJson.routes[1].bounds.southwest.lng..Value



//DISTANCIA - TXT
index++
arrGoogle[index].sGoogleMapsName = "Distancia Texto Total"
arrGoogle[index].sGoogleMapsValue = PersonalJson.routes[1].legs[1].distance.text..Value
grDistancia = arrGoogle[index].sGoogleMapsValue

//DISTANCIA - VALUE
index++
arrGoogle[index].sGoogleMapsName = "Distancia Valor Total"
arrGoogle[index].sGoogleMapsValue = PersonalJson.routes[1].legs[1].distance.value..Value




//DURACAO - TXT
index++
arrGoogle[index].sGoogleMapsName = "Duracao Texto Total"
arrGoogle[index].sGoogleMapsValue = PersonalJson.routes[1].legs[1].duration.text..Value
grTempo = arrGoogle[index].sGoogleMapsValue


//DISTANCIA - VALUE
index++
arrGoogle[index].sGoogleMapsName = "Duracao Valor Total"
arrGoogle[index].sGoogleMapsValue = PersonalJson.routes[1].legs[1].duration.value..Value



//ENDERECO INICIAL
index++
arrGoogle[index].sGoogleMapsName = "Endereço Completo Inicial"
arrGoogle[index].sGoogleMapsValue = PersonalJson.routes[1].legs[1].start_address..Value



//ENDERECO INICIAL LATITUDE
index++
arrGoogle[index].sGoogleMapsName = "Endereço Inicial Latitude"
arrGoogle[index].sGoogleMapsValue = PersonalJson.routes[1].legs[1].start_location.lat..Value
gloLatitudeOrigem = arrGoogle[index].sGoogleMapsValue


//ENDERECO INICIAL LONGITUDE
index++
arrGoogle[index].sGoogleMapsName = "Endereço Inicial Longitude"
arrGoogle[index].sGoogleMapsValue = PersonalJson.routes[1].legs[1].start_location.lng..Value
gloLongitudeOrigem = arrGoogle[index].sGoogleMapsValue




//ENDERECO FINAL
index++
arrGoogle[index].sGoogleMapsName = "Endereço Completo Final"
arrGoogle[index].sGoogleMapsValue = PersonalJson.routes[1].legs[1].end_address..Value


//ENDERECO FINAL LATITUDE
index++
arrGoogle[index].sGoogleMapsName = "Endereço Final Latitude"
arrGoogle[index].sGoogleMapsValue = PersonalJson.routes[1].legs[1].end_location.lat..Value
gloLatitudeDestino = arrGoogle[index].sGoogleMapsValue


//ENDERECO FINAL LONGITUDE
index++
arrGoogle[index].sGoogleMapsName = "Endereço Final Longitude"
arrGoogle[index].sGoogleMapsValue = PersonalJson.routes[1].legs[1].end_location.lng..Value
gloLongitudeDestino= arrGoogle[index].sGoogleMapsValue



//Steps
i is int = 0

FOR EACH x OF PersonalJson.routes[1].legs[1].steps

i+= 1

index++
arrGoogle[index].sGoogleMapsName = "Step ["+ i +"]"

index++
arrGoogle[index].sGoogleMapsName = "Step ["+ i +"] Latitude Inicial"
arrGoogle[index].sGoogleMapsValue = PersonalJson.routes[1].legs[1].steps[i].start_location.lat

index++
arrGoogle[index].sGoogleMapsName = "Step ["+ i +"] Longitude Inicial"
arrGoogle[index].sGoogleMapsValue = PersonalJson.routes[1].legs[1].steps[i].start_location.lng

index++
arrGoogle[index].sGoogleMapsName = "Step ["+ i +"] Latitude Final"
arrGoogle[index].sGoogleMapsValue = PersonalJson.routes[1].legs[1].steps[i].end_location.lat

index++
arrGoogle[index].sGoogleMapsName = "Step ["+ i +"] Longitude Final"
arrGoogle[index].sGoogleMapsValue = PersonalJson.routes[1].legs[1].steps[i].end_location.lng

index++
arrGoogle[index].sGoogleMapsName = "Step ["+ i +"] Distancia text"
arrGoogle[index].sGoogleMapsValue = PersonalJson.routes[1].legs[1].steps[i].distance.text

index++
arrGoogle[index].sGoogleMapsName = "Step ["+ i +"] Distancia value"
arrGoogle[index].sGoogleMapsValue = PersonalJson.routes[1].legs[1].steps[i].distance.value

index++
arrGoogle[index].sGoogleMapsName = "Step ["+ i +"] Duracao text"
arrGoogle[index].sGoogleMapsValue = PersonalJson.routes[1].legs[1].steps[i].duration.text

index++
arrGoogle[index].sGoogleMapsName = "Step ["+ i +"] Duracao value"
arrGoogle[index].sGoogleMapsValue = PersonalJson.routes[1].legs[1].steps[i].duration.value

index++
arrGoogle[index].sGoogleMapsName = "Step ["+ i +"] Instruções de Voz"
arrGoogle[index].sGoogleMapsValue = PersonalJson.routes[1].legs[1].steps[i].html_instructions

index++
arrGoogle[index].sGoogleMapsName = "Step ["+ i +"] Points Polyline Endcode Google"
arrGoogle[index].sGoogleMapsValue = PersonalJson.routes[1].legs[1].steps[i].polyline.points

index++
arrGoogle[index].sGoogleMapsName = "Step ["+ i +"] Travel Mode"
arrGoogle[index].sGoogleMapsValue = PersonalJson.routes[1].legs[1].steps[i].travel_mode


END

END

XmlJsonResultado = "OK"

ELSE

XmlJsonResultado = "Erro"

END

RESULT(XmlJsonResultado)


RESULTADO COM ARRAY É IGUAL





ESSE EXEMPLO USOU UMA TABLE DE MEMORIA DO TIPO STRUCTURE

ST_GoogleMaps is Structure
sGoogleMapsName is string
sGoogleMapsValue is string
END
arrGoogle is array of 5000 ST_GoogleMaps

OK, Voce pode fazer com isso o que voce fazia com Clarion e Queue Struct

--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 99949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/
Message modifié, 17 février 2018 - 01:09
Membre enregistré
2 867 messages
Popularité : +89 (91 votes)
Posté le 17 février 2018 - 00:40
PROCEDURE DESENVOLVIDA PELO CLIENTE RICARDO CASSOLATO

Procedure RotasGoogleMaps(enderecoOrigem is geoPosition, enderecoDestino is geoPosition)

//IF enderecoOrigem = "" OR enderecoDestino = "" THEN
// RESULT(Null)
//END
//enderecoOrigem = NoSpace(NoAccent(Replace(enderecoOrigem," ","+")))
//enderecoDestino = NoSpace(NoAccent(Replace(enderecoDestino," ","+")))

//---------------------------------------------//---------------------//
//-- para o uso das rotas e distancias local --// variaveis globais --//
//---------------------------------------------//---------------------//
GloVoceEnderecoLongo = "ERRO" //String
GloDestinoEnderecoLongo= "ERRO" //String
GloTempoDestino = "" //String
GloDistanciaDestino = "" //String
GloHtmlInstructions = "" //String
GloPoligonalGoogle = "" //String
GloDistanciaCarro = 0 //real
GloTempoCarro = 0 //real
GloNortelatitude = 0 //real
GloNorteLongitute = 0 //real
GloSullatitude = 0 //real
GloSulLongitute = 0 //real
//-------------------------------------------------------------//
//-- trata o endereço inicial e final que virão em lat/long ---//
//-------------------------------------------------------------//
//-23.1850109
sPosInicial is string = ""
sPosFinal is string = ""

sPosInicial = NoSpace(NumToString(enderecoOrigem..Latitude, "2.7f")) + "," + NoSpace(NumToString(enderecoOrigem..Longitude, "2.7f"))
sPosFinal = NoSpace(NumToString(enderecoDestino..Latitude, "2.7f")) + "," + NoSpace(NumToString(enderecoDestino..Longitude, "2.7f"))

//HTTPCreateForm("GoogleMaps")
//HTTPAddParameter("GoogleMaps","origin" , sPosInicial )
//HTTPAddParameter("GoogleMaps","destination", sPosFinal )
//HTTPAddParameter("GoogleMaps","language" , "pt-BR" )
//HTTPAddParameter("GoogleMaps","region" , "br" )
//HTTPAddParameter("GoogleMaps","units" , "metric" )
//HTTPAddParameter("GoogleMaps","key" , gGmapsKey )
//cGmRequest is httpRequest
//cGmRequest..URL = "https://maps.googleapis.com/maps/api/directions/xml"
//cGmRequest..Method = httpGet
//cGmResponse is httpResponse = HTTPSendForm("GoogleMaps", cGmRequest)
//IF cGmResponse..StatusCode <> 200 THEN // Se não funcionou
// RESULT False
//END
//ResGoogleMaps is string = cGmResponse..Content //HTTPGetResult(httpResult)
////Info(SysCacheExternalStorage(1),SysDirExternalStorage(1,ssePublicDocument) , SysRemovableExternalStorage(1) )
//IF NOT InSimulatorMode() THEN
// If fSaveText("/mnt/sdcard/Download/gmaps/resultadoGMaps.txt",ResGoogleMaps) THEN
// //Info("Arquivo Salvo com sucesso!")
// END
//Else
// IF fSaveText("resultadoGMaps.txt",ResGoogleMaps) THEN
// //Info("Arquivo Salvo com sucesso!")
// END
//End
////Info(ResGoogleMaps)
//xmlGoogle is xmlDocument = XMLOpen(ResGoogleMaps, fromString)
////fSaveText("XMLGOOGLEMAPSDIRECTIONS.xml",ResGoogleMaps)

//---------------------------------------------------------//
//-- teste com json --//
//---------------------------------------------------------//
UrlRotaJson is string = "https://maps.googleapis.com/maps/api/directions/json?origin="+sPosInicial+"&destination="+sPosFinal+"&sensor=false&mode=driving&key="+gGmapsKey
cGmRequestJson is httpRequest
cGmRequestJson..URL = UrlRotaJson
cGmRequestJson..Method = httpGet
cGmResponseJson is httpResponse = HTTPSend(UrlRotaJson)
IF cGmResponseJson..StatusCode <> 200 THEN // Se não funcionou
RESULT False
END
ResGoogleMapsJson is ANSI string = cGmResponseJson..Content //HTTPGetResult(httpResult)
//Info(ResGoogleMaps)
vJsonGoogle is Variant = JSONToVariant(ResGoogleMapsJson)
//fSaveText("JsonGOOGLEMAPSDIRECTIONS.txt",ResGoogleMapsJson)
//------------------------------------------------------------------//

//----------------------------------------------//
//--- seta os valores nas variaveis globais -- //
//----------------------------------------------//
GloVoceEnderecoLongo = vJsonGoogle.routes[1].legs[1].start_address //xmlGoogle.DirectionsResponse.route.leg.start_address
GloDestinoEnderecoLongo = vJsonGoogle.routes[1].legs[1].end_address //xmlGoogle.DirectionsResponse.route.leg.end_address
GloTempoCarro = vJsonGoogle.routes[1].legs[1].duration.value //xmlGoogle.DirectionsResponse.route.leg.duration.value
GloTempoDestino = vJsonGoogle.routes[1].legs[1].duration.text //xmlGoogle.DirectionsResponse.route.leg.duration.text
GloDistanciaCarro = vJsonGoogle.routes[1].legs[1].distance.value //xmlGoogle.DirectionsResponse.route.leg.distance.value
GloDistanciaDestino = vJsonGoogle.routes[1].legs[1].distance.text //xmlGoogle.DirectionsResponse.route.leg.distance.text
GloPoligonalGoogle = vJsonGoogle.routes[1].overview_polyline.points //xmlGoogle.DirectionsResponse.route.overview_polyline.points
GloNortelatitude = vJsonGoogle.routes[1].bounds.northeast.lat //xmlGoogle.DirectionsResponse.route.bounds.northeast.lat
GloNorteLongitute = vJsonGoogle.routes[1].bounds.northeast.lng //xmlGoogle.DirectionsResponse.route.bounds.northeast.lng
GloSullatitude = vJsonGoogle.routes[1].bounds.southwest.lat //xmlGoogle.DirectionsResponse.route.bounds.southwest.lat
GloSulLongitute = vJsonGoogle.routes[1].bounds.southwest.lng //xmlGoogle.DirectionsResponse.route.bounds.southwest.lng
RESULT True


--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 99949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/
Membre enregistré
2 867 messages
Popularité : +89 (91 votes)
Posté le 17 février 2018 - 01:10
//Para limpar o mapa e criar novas linhas e posições é necessario excluir as antigas marcações.
MapDeleteMarker(MAP_GoogleMaps)
MapDeleteAll(MAP_GoogleMaps)


--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 99949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/
Membre enregistré
2 867 messages
Popularité : +89 (91 votes)
Posté le 19 mars 2018 - 16:07


--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 99949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/