PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 24 → WX - Função GEO IP, localize pelo IP o "Local Aproximado" (Endereço, Latitude e Longitude)
WX - Função GEO IP, localize pelo IP o "Local Aproximado" (Endereço, Latitude e Longitude)
Débuté par adrianoboller, 15 juil. 2015 17:39 - 4 réponses
Membre enregistré
2 962 messages
Popularité : +89 (91 votes)
Posté le 15 juillet 2015 - 17:39
Procedure WS_GeoIpLatitudeLongitude(LOCAL IP, LOCAL DebugSn)

ok is boolean = False

//Exemplo: "http://www.geoiptool.com/pt/201.21.151.121"

//Nome do Host: c9159779.virtua.com.br
//IP Address: 201.21.151.121
//País: Brazil brazil
//Código do país: BR (BRA)
//Região: Parana
//Cidade: Curitiba
//Código postal:
//Código tel.: +55
//Longitude: -49.25
//Latitude: -25.4167

//<table width="297" height="300" border="0" cellpadding="4" cellspacing="0" class="tbl_style">
//<tr>
//<td align="right"><span class="arial">Nome do Host:</span></td>
//<td width="198" align="left" class="arial_bold">c9159779.virtua.com.br</td>
//</tr>
//<tr>
//<td align="right"><span class="arial">IP Address:</span></td>
//<td align="left" class="arial_bold">201.21.151.121</td>
//</tr>
//<tr>
//<td align="right"><span class="arial">País:</span></td>
//<td align="left" class="arial_bold"><a href="http://en.wikipedia.org/wiki/brazil" target="_blank"> Brazil</a> <img src='/flags/br.gif' alt="brazil" align="absmiddle" ></td>
//</tr>
//<tr>
//<td align="right"><span class="arial">Código do país:</span></td>
//<td align="left" class="arial_bold">BR (BRA)</td>
//</tr>
//<tr>
//<td align="right"><span class="arial">Região:</span></td>
//<td align="left" class="arial_bold"><a href="http://en.wikipedia.org/wiki/Parana" target="_blank">Parana</a></td>
//</tr>
//<tr>
//<td align="right"><span class="arial">Cidade:</span></td>
//<td align="left" class="arial_bold">Curitiba</td>
//</tr>
//<tr>
//<td align="right"><span class="arial">Código postal:</span></td>
//<td align="left" class="arial_bold"></td>
//</tr>
//<tr>
//<td align="right"><span class="arial">Código tel.:</span></td>
//<td align="left" class="arial_bold"><a href="http://en.wikipedia.org/wiki/Area_code#Brazil">+55</a></td>
//</tr>
//<tr>
//<td align="right"><span class="arial">Longitude:</span></td>
//<td align="left" class="arial_bold">-49.25</td>
//</tr>
//<tr>
//<td align="right"><span class="arial">Latitude:</span></td>
//<td align="left" class="arial_bold">-25.4167</td>
//</tr>
//</table>

//IP = "201.21.151.121"

Url is string = "http://www.geoiptool.com/pt/"+ IP

Inicio, Fim is int = 0

sXml, Latitude, Longitude, Busca, sBuscaTD is string = ""

HTTPTimeOut(GloHTTPTimeOut)

ok = HTTPRequest(Url)

IF ok = True THEN

sXml = HTTPGetResult(httpResult)

sXml = Replace(sXml,"Matriz,","")
sXml = Replace(sXml,"Matriz","")

IF Length(sXml) > 0 THEN

Busca = "Longitude:"

Inicio = PositionOccurrence(sXml,Busca,firstRank)

Busca = "Latitude:"

Fim = PositionOccurrence(sXml,Busca,firstRank) + 100

sXml = Middle(sXml,Inicio, Fim-Inicio)

sXml = Replace(sXml, " ", "")

sXml = Replace(sXml, "<10>", "")

sXml = Replace(sXml, "<br>", "")

sXml = Replace(sXml, Charact(13), "")

sXml = Replace(sXml, Charact(10), "")

sXml = Replace(sXml, Charact(34), "")

sXml = Replace(sXml, Charact(13)+Charact(10), "")

sXml = Replace(sXml, "</span></td><tdalign=leftclass=arial_bold>", "")

sXml = Replace(sXml, "</td></tr><tr><tdalign=right><spanclass=arial>", "; ")

sXml = Replace(sXml, "</td>", "")

Inicio = PositionOccurrence(sXml,"Latitude:",firstRank,IgnoreCase)

Longitude = Middle(sXml,11,Inicio-13)

Latitude = Middle(sXml,Inicio+9,Length(sXml))

GloVoceLatitude = Latitude

GloVoceLongitude = Longitude

sXml = Latitude +"; "+ Longitude

IF DebugSn = "S"
fSaveText("c:\latlong.txt",sXml)
END

END

END

RESULT(sXml)
Membre enregistré
2 962 messages
Popularité : +89 (91 votes)
Posté le 15 juillet 2015 - 17:40
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)
Membre enregistré
2 962 messages
Popularité : +89 (91 votes)
Posté le 15 juillet 2015 - 17:41
Procedure WS_CEP_EnderecoRetornaLatLonGoogleMaps(LOCAL Endereco, LOCAL OrigemDestino, LOCAL DebugSN)

IF GloDebugSN = "S" THEN
Info("WS_CEP_EnderecoRetornaLatLonGoogleMaps")
DebugSN = "S"
END

ok is boolean = False

GloOutrasTelas = "S"

Retorno is string = ""

ChangeCharset(charsetOccidental) // SEM ACENTO


inicio, fim is int = 0

//Exemplo: http://maps.google.com/maps/api/geocode/json?address=670+Rua+Dias+Rocha+Filho,+Alto+da+XV,+Curitiba,+PR&sensor=true

Endereco = NoAccent(Endereco)

Endereco = Replace(Endereco," ","+")

Endereco = "http://maps.google.com/maps/api/geocode/xml?address="+Endereco+"&sensor=true"

HTTPTimeOut(GloHTTPTimeOut)

IF DebugSN = "S"
Info("Envio: "+Endereco)
END


ok = HTTPRequest(Endereco)


IF ok = True THEN

Retorno = HTTPGetResult(httpResult)

ChangeCharset(charsetOccidental) // SEM ACENTO

Retorno = Capitalize(WS_RemoveAcentos(Retorno))


Retorno = Replace(Retorno,"Matriz,","")

Retorno = Replace(Retorno,"Matriz","")

IF DebugSN = "S"
Info("Retorno: "+Retorno)
END

//Retorno da Consulta
IF DebugSN = "S" AND InSimulatorMode() = False THEN
IF InAndroidMode() = True
fSaveText("/mnt/sdcard/TaxiFv/Arquivos/WS_CEP_EnderecoRetornaLatLonGoogleMaps.txt",Retorno)
END
END

IF Retorno <> Null THEN


Retorno = Replace(Retorno,Charact(34),"")

//info(Return_Json)

//Retorno Esperado
//12345678901234567890
//lat : -25.4259127,
//lng : -49.249879

IF PositionOccurrence(Retorno,"OVER_QUERY_LIMIT",firstRank,FromBeginning) > 0 AND DebugSN = "S" THEN
NextTitle("Atenção")
Info("Excedeu a quantidade de pesquisas no google maps.")
ELSE

//Endereco
IF PositionOccurrence(Retorno,"<formatted_address>",firstRank,IgnoreCase) > 0 THEN
inicio = PositionOccurrence(Retorno,"<formatted_address>",firstRank,IgnoreCase) + 19
fim = PositionOccurrence(Retorno,"</formatted_address>",firstRank,IgnoreCase)

IF OrigemDestino = "O"
GloVoceEnderecoLongo = Middle(Retorno,inicio,fim-inicio)
ELSE IF OrigemDestino = "D"
GloDestinoEnderecoLongo = Middle(Retorno,inicio,fim-inicio)
END

END

//Latitude
IF PositionOccurrence(Retorno,"<lat>",firstRank,IgnoreCase) > 0 THEN
inicio = PositionOccurrence(Retorno,"<lat>",firstRank,IgnoreCase) + 5
fim = PositionOccurrence(Retorno,"</lat>",firstRank,IgnoreCase) - 1
GloLatitudeLocalizada = Val(Middle(Retorno,inicio,fim-inicio),"d")
IF OrigemDestino = "O"
GloVoceLatitude = GloLatitudeLocalizada
ELSE IF OrigemDestino = "D"
GloDestinoLatitude = GloLatitudeLocalizada
END
END

//Longitude
IF PositionOccurrence(Retorno,"<lng>",firstRank,IgnoreCase) > 0 THEN
inicio = PositionOccurrence(Retorno,"<lng>",firstRank,IgnoreCase) + 5
fim = PositionOccurrence(Retorno,"</lng>",firstRank,IgnoreCase) - 1
GloLongitudeLocalizada = Val(Middle(Retorno,inicio,fim-inicio),"d")
IF OrigemDestino = "O"
GloVoceLongitude = GloLongitudeLocalizada
ELSE IF OrigemDestino = "D"
GloDestinoLongitude = GloLongitudeLocalizada
END
END

//Retorno
IF OrigemDestino = "O" THEN
Retorno = GloVoceLatitude +";"+ GloVoceLongitude
ELSE IF OrigemDestino = "D"
Retorno = GloDestinoLatitude +";"+ GloDestinoLongitude
END

END


END



//Historico
//HReadSeekFirst(t008_inicial,t008_inicial.t008_codigo,1)
//IF HFound(t008_inicial) = True
//t008_inicial.t008_codigo = 1
//IF OrigemDestino = "O"
//t008_inicial.t008_endereco = GloVoceEnderecoLongo
//t008_inicial.t008_numero = 0
//t008_inicial.t008_latitude = GloVoceLatitude
//t008_inicial.t008_longitude= GloVoceLongitude
// else IF OrigemDestino = "D"
//t008_inicial.t008_endereco = GloBuscaEnderecoLongo
//t008_inicial.t008_numero = 0
//t008_inicial.t008_latitude = GloBuscaLatitude
//t008_inicial.t008_longitude= GloBuscaLongitude
//end
//HModify(t008_inicial)
//END


IF DebugSN = "S"
Info("Retorno", Retorno)
END

END

GloOutrasTelas = ""

RESULT(Retorno)
Membre enregistré
2 962 messages
Popularité : +89 (91 votes)
Posté le 18 juillet 2015 - 17:46
A Url sofreu uma mudança, altere para essa linha:

Url is string = "https://geoiptool.com/pt/…="+ IP
Membre enregistré
2 962 messages
Popularité : +89 (91 votes)
Posté le 17 octobre 2019 - 21:37
Procedure New_Capitalize(Texto)

x is int = 0

Nome, newNome is string =""

IF Texto <> "" THEN

nQtdeEspaco is int = StringCount(Texto," ")

LOOP(nQtdeEspaco)
x++
Nome = ExtractString(Texto,x," ",FromBeginning)
Nome = Upper(Middle(Nome,1,1)) + Middle(Nome,2,Length(Nome)) + " "
newNome += Nome
END

newNome = Replace(newNome," Da ", " da ")

newNome = Replace(newNome," Das ", " das ")

newNome = Replace(newNome," De ", " de ")

newNome = Replace(newNome," Do ", " do ")

newNome = Replace(newNome," Dos ", " dos ")

END

RESULT newNome


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