Clipper On Line • Ver Tópico - Geo location do google
Página 1 de 1

Geo location do google

MensagemEnviado: 04 Nov 2020 14:38
por JoséQuintas
Do fórum harbour-users.

//-----------------7
FUNCTION GetGeocode( cAddress, cKey)
LOCAL cCoordinates:= "", nLatitude:= 0, nLongitude:= 0
LOCAL cUrl, oUrl, oClient, cChunk, cData

//1600+Amphitheatre+Parkway,+Mountain+View,+CA

cAddress:= STRTRAN( cAddress, " ", "+" )
cUrl:= "https://maps.googleapis.com/maps/api/geocode/xml?key="+cKey+"&address="+ALLTRIM(cAddress)+"&sensor=false"

oUrl := TUrl():New( cUrl )
oClient := TIPClientHTTP():new( oUrl )
IF oClient:Open()
   cChunk:= oClient:Read()
   cData:= ""
   WHILE !EMPTY( cChunk )
      cData+= cChunk
      cChunk:= oClient:Read()
   ENDDO
   IF LEN( cData ) > 0
      cCoordinates:= getTAG( "geometry", cData )
      cCoordinates:= getTAG( "location", cCoordinates )
      nLatitude:= VAL( getTAG( "lat", cCoordinates ) )
      nLongitude:= VAL( getTAG( "lng", cCoordinates ) )
   ENDIF

   oClient:Close()
ENDIF
RETURN { nLatitude, nLongitude }

//------------------------
FUNCTION getTAG(xtag,xml)
LOCAL xret, xpos, xini:= 1, xfim
xpos:= HB_AT("<"+xtag+">",xml,xini)
IF EMPTY( xpos )
   xpos:= HB_AT("<"+xtag+" ",xml,xini)
ENDIF
IF xpos > 0
   xpos:= xpos+LEN(xtag)+2
   xfim:= HB_AT("</"+xtag+">",xml,xpos)
   xret:= SUBS(xml,xpos,xfim-xpos)
ELSE
   xret:= ""
ENDIF
RETURN xret

Geo location do google

MensagemEnviado: 04 Nov 2020 19:34
por asimoes
Como é que funciona isso?