sábado, 9 de janeiro de 2016

Procedure RotasGoogleMaps, Retorna de dois endereços o tempo estimado, distância, norte, sul,etc..

http://forum.pcsoft.fr/fr-FR/pcsoft.br.windev/856-procedure-rotasgooglemaps-retorna-dois-enderecos-tempo-estimado-distancia/read.awp


Procedure RotasGoogleMaps, Retorna de dois endereços o tempo estimado, distância, norte, sul, as direçôes a serem tomadas e os endereços completos formatados pelo google





Procedure WS_RotasGoogleMaps(enderecoOrigem is string, enderecoDestino is string) : string

IF enderecoOrigem = "" OR enderecoDestino = "" THEN
RESULT(Null)
END

//GloVoceEnderecoLongo is string
//GloVoceEndereco is string
//GloVoceNumero is string
//GloDestinoEnderecoLongo is string
//GloDestinoEndereco is string
//GloDestinoNumero is string
//GloValorBandeira01 is real
//GloValorBandeira02 is real
//GloTaxaRetorno is real
//GloTempoCarro is real
//GloDistanciaCarro is real
//GloNortelatitude is real
//GloNorteLongitute is real
//GloSullatitude is real
//GloSulLongitute is real
//GloTempoDestino is string
//GloPoligonalGoogle is string
//GloDistanciaDestino is string
//GloHtmlInstructions is string

//Limpa variaveis
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

HTTPCreateForm("GoogleMaps")
HTTPAddParameter("GoogleMaps","origin", enderecoOrigem)
HTTPAddParameter("GoogleMaps","destination", enderecoDestino)
HTTPAddParameter("GoogleMaps","language", "pt-BR")
HTTPAddParameter("GoogleMaps","region", "br")
HTTPAddParameter("GoogleMaps","units", "metric")
HTTPAddParameter("GoogleMaps","key","AIzaSyDbSVKYPwB1a-_vPbDzAr6LgAfIj4iW2hc")

cMyRequest is HTTPRequest
cMyRequest..URL = "https://maps.googleapis.com/maps/api/directions/xml"
cMyRequest..Method = httpGet

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

IF cMyResponse..StatusCode <> 200 THEN // Se não funcionou
RESULT(Null)
END

xmlGoogle is XMLDocument = XMLOpen(cMyResponse..Content, fromString)
IF NOT xmlGoogle.DirectionsResponse.status..Text ~= "OK" THEN
RESULT(Null)
END

//Lendo nos unicos
GloVoceEnderecoLongo = xmlGoogle.DirectionsResponse.route.leg.start_address
GloDestinoEnderecoLongo = xmlGoogle.DirectionsResponse.route.leg.end_address
GloTempoCarro = xmlGoogle.DirectionsResponse.route.leg.duration.value
GloTempoDestino = xmlGoogle.DirectionsResponse.route.leg.duration.text
GloDistanciaCarro = xmlGoogle.DirectionsResponse.route.leg.distance.value
GloDistanciaDestino = xmlGoogle.DirectionsResponse.route.leg.distance.text
GloPoligonalGoogle = xmlGoogle.DirectionsResponse.route.overview_polyline.points
GloNortelatitude = xmlGoogle.DirectionsResponse.route.bounds.northeast.lat
GloNorteLongitute = xmlGoogle.DirectionsResponse.route.bounds.northeast.lng
GloSullatitude = xmlGoogle.DirectionsResponse.route.bounds.southwest.lat
GloSulLongitute = xmlGoogle.DirectionsResponse.route.bounds.southwest.lng

//Loop nos nós do xml
Resultado is string
Contador is int = 1
FOR EACH legNode OF xmlGoogle.DirectionsResponse.route.leg
IF legNode..Name = "step" THEN
HTML is string = legNode.html_instructions
Distancia is int = legNode.distance.value
Resultado += Contador + ". " + HTML + " [" + Distancia + "]" + CR
Contador++
END
END

GloHtmlInstructions = Resultado

RESULT(Resultado)





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





Nenhum comentário:

Postar um comentário

Teste

Teste
teste