PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV Mobile 24 → Endereco das Coordenadas Latitude e Longitude
Endereco das Coordenadas Latitude e Longitude
Débuté par adrianoboller, 18 nov. 2014 13:46 - Aucune réponse
Membre enregistré
2 958 messages
Popularité : +89 (91 votes)
Posté le 18 novembre 2014 - 13:46
Procedure WS_CEP_EnderecoDasCoordenadas(LOCAL pLatitude is string, LOCAL pLongitude is string, LOCAL DebugSN)

IF GloDebugSN = "S" THEN
Info("WS_CEP_EnderecoDasCoordenadas")
DebugSN = "S"
END
//pLatitude= "-25.431637"
//plongitude ="-49.203203"
NextTitle("Atenção")

ok is boolean = False
GloEnderecoOK = False

Endereco, RetJson is string = ""
IF pLatitude <> 0 AND pLongitude <> 0 AND pLatitude <> Null AND pLongitude <> Null THEN

Url is string = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" + pLatitude + "," + pLongitude + "&sensor=true"

IF DebugSN = "S"
Info("01",Url)
END

HTTPTimeOut(GloHTTPTimeOut)


ok = HTTPRequest(Url)

IF ok = True THEN

ChangeCharset(charsetOccidental) // SEM ACENTO


RetJson = WS_Android_IOS_HTTPGetResult()//HTTPGetResult(httpResult)
IF Length(RetJson) = 0 THEN

ok= False
ELSE



IF DebugSN = "S"
Info(Url,RetJson)
END

///// teste
//TagEndac is string
//io is int = PositionOccurrence(RetJson, TagEndac, firstRank, IgnoreCase )// + Length(TagEndac)
//
//
//TagEndac = Middle(retjson,PositionOccurrence(RetJson,"""address_components"" :", firstRank, IgnoreCase ),Length(RetJson))
//blocoJson is string = Middle( tagEndac,1,PositionOccurrence(TagEndac,"],", firstRank, IgnoreCase ))
////<Result> = ExtractString(<Initial String> , <Rank> [, <Separator> [, <Browse Direction>]])
//
// if (blocoJson<> "") THEN
//Endereco = ExtractString(blocoJson,firstRank,"""types"" : [ ""street_number"" ]",FromEnd)
//END
//
////Pega endereço (entre duas aspas)
//IF io> 0 THEN
//Endereco = ExtractString(RetJson[[io TO]],4,"""")
//GloEnderecoOK = True
//
//END
////teste
//


TagEnd is string = """formatted_address"" :"
i is int = PositionOccurrence(RetJson, TagEnd, firstRank, IgnoreCase ) + Length(TagEnd)
Endereco =""
//Pega endereço (entre duas aspas)
IF i> 0 THEN
Endereco = ExtractString(RetJson[[i TO]],2,"""")
GloEnderecoOK = True

END

IF Endereco = "" OR RetJson = "ERRO" THEN
// busca por XML
GloEnderecoOK = False
Url = "http://maps.googleapis.com/maps/api/geocode/xml?latlng=" + pLatitude + "," + pLongitude + "&sensor=true"

IF DebugSN = "S"
Info("02",Url)
END

HTTPTimeOut(GloHTTPTimeOut)

ok = HTTPRequest(Url)
IF ok = True THEN

RetXml is string = WS_Android_IOS_HTTPGetResult()// HTTPGetResult(httpResult)

IF Length(RetXml) = 0 THEN

ok= False
ELSE

IF DebugSN = "S"
Info("Xml:",RetXml)
END

//<formatted_address>Rua Professora Antonia Reginato Vianna, 442 - Capão da Imbuia, Cajuru, Curitiba - PR, 82810-300, Brasil</formatted_address>

IF PositionOccurrence(RetXml,"<formatted_address>",firstRank) > 0 THEN

//Endereço
nPosicaoInicial is int = PositionOccurrence(RetXml,"<formatted_address>",firstRank) + Length("<formatted_address>")
nPosicaoFinal is int = PositionOccurrence(RetXml,"</formatted_address>",firstRank) + Length("</formatted_address>")
nPosicaoFinal = nPosicaoFinal - nPosicaoInicial
Endereco = Middle(RetXml,nPosicaoInicial,nPosicaoFinal)
GloEnderecoOK = True

END
END
END
END
END
END

IF ok = False THEN
Popup(GloMsgSemInternet,"L")
END



Endereco = WS_RemoveAcentos(Endereco)

END





RESULT (Endereco)