Jump to content
Fivewin Brasil

Pegar locaclização usando Latitude e longitude


EDUTEK

Recommended Posts

Boa tarde

 

Alguém tem algum exemplo de como pegar a localização tendo a latitude e longitude.

Tenho um programa de ponto de motorista, cada marcação ele grava a latitude e longitude, preciso informar pelo menos aproximadamente o local que ele efetuou a marcação.

O programa do Tablet que ele faz a marcação não fui eu que desenvolvi, só montei o projeto, mas a parte da retaguarda é minha a programação.

ai queria saber por exemplo onde ele encerrou a jornada do dia dele.

Alguém tem um exemplo ?

 

 

Grato.

Link to comment
Share on other sites

conforme o João passou, procurei lá e consegui achar uma forma  segue abaixo

function orion_jornada_AchaEndereco(mLat, mLong)
   local cGoogleURL := "https://nominatim.openstreetmap.org/reverse?format=xml&"
   local cAddress   := "lat="+alltrim(mLat)+"&lon="+alltrim(mLong)
   local aReturn, i, cTxt := ""
   if empty(mLat)
         mLat := jornada->latitudegps
         mLong := Jornada->longitudegps         
         cAddress   := "lat="+alltrim(mLat)+"&lon="+alltrim(mLong)
   endif         
  // aReturn := hb_jsonDecode( WebPageContents( cGoogleURL + cAddress) )   // *** Change this *** 
   cDocXML := WebPageContents( cGoogleURL + cAddress)
*   hb_jsondecode( aReturn, @aReturn ) && se lá na URL vc colocar format "json" - eu uso "XML"
   if !empty(cDocXML)
      mRodovia  := LerTag(cDocxml, "road")       
      mCidade   := LerTag(cDocxml, "town")         
      mArea     := LerTag(cDocxml, "municipality")         
      mEstado   := LerTag(cDocxml, "state")         
      mRegiao   := LerTag(cDocxml, "region")
      mRodovia  := iif(len(rtrim(mrodovia))>0,mRodovia+", ","")                         
      mCidade   := iif(len(rtrim(mCidade))>0,mCidade+", ","")                               
      mestado   := iif(len(rtrim(mEstado))>0,mEstado+", ","")                               
      mRegiao   := iif(len(rtrim(mRegiao))>0,mRegiao+", ","")                               
      cTxt1     := mRodovia + mcidade + mEstado + mRegiao + mArea
      cTXT      := U8ToUni(cTXT1,"UTYPE_ANSI")
      if len(alltrim(ctxt)) < 10
         cTxt:="Localização não Encontrada"      
      endif
   else   
      cTxt:="Localização não Encontrada"
   endif
   dbselectarea("jornada")
   mregistro := jornada->( recno())
   grava_dados("A","jornada",{ "local" }, { cTxt }, alias(), "S")
return nil

 

Link to comment
Share on other sites

5 horas atrás, kapiaba disse:

Good, que eu informo aqui: 

mLat, mLong  ???

Latitude e longitude e:  -22.63458 , -47,30005  -

pois minha aplicação recebe essas informações dos tablets nos caminhões, e ai pro pessoal de controle aqui eles necessitam saber onde foi o apontamento,

ai converto isso num endereço.

Link to comment
Share on other sites

Seria isso ?

#include "fivewin.ch"
Function Main()
   Orion_jornada_AchaEndereco('-23.820724', '-45.370145') //LATITUDE E LONGITUDE
Return Nil

Function orion_jornada_AchaEndereco(mLat, mLong)
   local cGoogleURL := "https://nominatim.openstreetmap.org/reverse?format=xml&"
   local cAddress   := "lat="+alltrim(mLat)+"&lon="+alltrim(mLong)
   local cXml := WebPageContents( cGoogleURL + cAddress)

   XBrowseXML(cXml)   //fw23.07
Return Nil

 

Link to comment
Share on other sites

Edutek, faça isso funcionar corretamente, PSL. Seu exemplo não está nada bom...

[code]
#include "fivewin.ch"

FUNCTION Main()

   LOCAL mLat, mLong

   // Latitude e longitude e:  -22.63458 , -47,30005

   mLat  := "-22.63458"
   mLong := "-47,30005"

   orion_jornada_AchaEndereco( mLat, mLong )

RETURN NIL

FUNCTION orion_jornada_AchaEndereco( mLat, mLong )

   LOCAL CDOCXML, MRODOVIA, MCIDADE, MAREA, MESTADO, MREGIAO, CTXT1, ;
         MREGISTRO, NI, CTEMP
   LOCAL cGoogleURL := "https://nominatim.openstreetmap.org/reverse?format=xml&"
   LOCAL cAddress   := "lat=" + AllTrim( mLat ) + "&lon=" + AllTrim( mLong )
   LOCAL aReturn, i, cTxt := ""

   IF Empty( mLat )

      mLat := jornada->latitudegps
      mLong := Jornada->longitudegps

      cAddress   := "lat=" + AllTrim( mLat ) + "&lon=" + AllTrim( mLong )

   ENDIF

   // aReturn := hb_jsonDecode( WebPageContents( cGoogleURL + cAddress) )   // *** Change this ***
   cDocXML := WebPageContents( cGoogleURL + cAddress )

   // hb_jsondecode( aReturn, @aReturn ) && se lá na URL vc colocar format "json" - eu uso "XML"
   IF .NOT. Empty( cDocXML )

      ? cDocXML  // NAO RETORNOU POHHA NENHUMA. kkkkkk

      mRodovia  := LerTag( cDocxml, "road" )
      mCidade   := LerTag( cDocxml, "town" )
      mArea     := LerTag( cDocxml, "municipality" )
      mEstado   := LerTag( cDocxml, "state" )
      mRegiao   := LerTag( cDocxml, "region" )

      mRodovia  := iif( Len( RTrim( mrodovia ) ) > 0, mRodovia + ", ", "" )
      mCidade   := iif( Len( RTrim( mCidade ) ) > 0, mCidade + ", ", "" )
      mestado   := iif( Len( RTrim( mEstado ) ) > 0, mEstado + ", ", "" )
      mRegiao   := iif( Len( RTrim( mRegiao ) ) > 0, mRegiao + ", ", "" )

      cTxt1     := mRodovia + mcidade + mEstado + mRegiao + mArea

      // QUE POHHA E ESSA?
      // cTXT      := U8ToUni( cTXT1, "UTYPE_ANSI" )

      IF Len( AllTrim( ctxt ) ) < 10

         cTxt := "Localização não Encontrada"

      ENDIF

   ELSE

      cTxt := "Localização não Encontrada"

   ENDIF

   /* QUAL A ESTRUTURA DESTE BANCO DE DADOS?
   dbSelectArea( "jornada" )

   mregistro := jornada->( RecNo() )
   */

   grava_dados( "A", "jornada", { "local" }, { cTxt }, Alias(), "S" )

   XBROWSE( cTxt1 )

RETURN NI

FUNCTION LERTAG( MsgRetWs, cNode ) // ESTA CORRETO?

   LOCAL cData:=""
   LOCAL nPos,nPos1,cTempo, CTEMP

   WHILE( .T. )

      SYSREFRESH()

      nPos := At("<"+cNode+">",MsgRetWs)

      cTemp:=Substr(MsgRetWs,nPos+len(cNode)+2)

      If At("<"+cNode+">",cTemp)!=0

         nPos1 := At("</"+cNode+">",cTemp)

         cTemp := Substr(cTemp,nPos1+len(cNode)+3)

         MsgRetWs := cTemp

      Else

         Exit

      Endif

      SysRefresh()

   ENDDO

   nPos1 := At("</"+cNode+">",MsgRetWs)

   If nPos!=-0.and.nPos1!=0

      cData := Substr(MsgRetWs,nPos+Len(cNode)+2,nPos1-(nPos+Len(cNode)+2))

   Endif

RETURN( cData )

FUNCTION GRAVA_DADOS() // PONHA A ORIGINAL

RETURN NIL

// FIN / END
[/code]

Regards, saludos.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...