Page 1 of 1

Fivewin con Google Maps

Posted: Mon Jan 18, 2016 11:42 am
by Loren
Compañeros, buenas:

Tengo una aplicación que en la ficha de clientes, dispone de un boton donde se abre una nueva ventana y llama a Google Maps mostrando en tiempo de ejecución un mapa con la localización exacta de la dirección que se teclea en la ficha de clientes. Lo hago todo mediante "oActiveX:Do" y gracias a un post que se publicó hace años en este mismo foro.

Desde hace años funcionaba perfecto... pero desde hace unos meses para acá, la búsqueda se queda bloqueada y paraliza el EXE. Es problable que Google haya cambiado los algoritmos de búsqueda... o algo así.

¿Alguien dispone de algo parecido y que le funcione?

Mil gracias.
LORENZO.

Re: Fivewin con Google Maps

Posted: Mon Jan 18, 2016 11:57 am
by karinha
Translate please for spanish.

Code: Select all

// Ideia original:
// http://www.pctoledo.com.br/forum/viewtopic.php?f=1&t=15482
// Special thanks ao autor do topico: Billy1943.

#Include "FiveWin.ch"
#Include "Directry.ch"

STATIC lSaida := .F., lLigaBotao := .F.

FUNCTION Google_Rua()

   LOCAL oWnd, oActiveX, oFnt, oFont, nKey := VK_RETURN
   LOCAL cEvents := "", cCookieUser
   LOCAL oMapa, mde_uf, mpara_uf, mde_cid, mpara_cid, mde_rua, mpara_rua
   LOCAL oGet1, oGet2, oGet3, oGet4, oBusca, oSaida, oDlg, msearch

   /*
   mpara_uf  := "SP" // uf
   mpara_cid := "SAO PAULO"//cidade
   mpara_rua := "RUA ROCHA"//rua
   */

   mpara_uf  := space(2)
   mpara_cid := space(40)  // PINDAMONHANGABA
   mpara_rua := space(50)

   SetGetColorFocus()

   SkinButtons()

   DEFINE FONT oFnt   NAME "Ms Sans Serif" SIZE 0,  14 BOLD //UnderLine
   DEFINE FONT oFont  NAME "Ms Sans Serif" SIZE 0, -14 BOLD //UnderLine

   DEFINE DIALOG oDlg TITLE "Buscar Rua no Google Maps" ;
          FROM 0,0 TO 304, 480 PIXEL COLORS CLR_BLACK, CLR_WHITE TRANSPARENT

   oDlg:lHelpIcon := .F.

   Set( _SET_INSERT, ! Set( _SET_INSERT ) )

   //@ 11, 01 say "PROCURAR :"
   @ 1, 2 SAY "PROCURAR A RUA:" OF oDlg UPDATE FONT oFont ;
          COLORS CLR_HRED, CLR_WHITE

   //@ 13, 01 say "Estado ..:" get mpara_uf picture "@!"
   @ 2, 2 SAY "Estado ..:" OF oDlg UPDATE FONT oFnt ;
          COLORS CLR_HBLUE, CLR_WHITE

   @ 30, 50 GET oGet1 VAR mpara_uf OF oDlg PIXEL SIZE 25, 12 PICTURE "@!" ;
            CENTER UPDATE FONT oFnt COLORS CLR_BLACK, CLR_WHITE           ;
            VALID VALIDA_GET1( mpara_uf )

   //@ 14, 01 say "Cidade ..:" get mpara_cid picture "@!"
   @ 3, 2 SAY "Cidade ..:" OF oDlg UPDATE FONT oFnt ;
          COLORS CLR_HBLUE, CLR_WHITE

   @ 45, 50 GET oGet2 VAR mpara_cid OF oDlg PIXEL SIZE 175, 12 PICTURE "@!" ;
            UPDATE FONT oFnt COLORS CLR_BLACK, CLR_WHITE                    ;
            VALID VALIDA_GET2( mpara_cid )

   //@ 15, 01 say "Endere‡o :" get mpara_rua picture "@!"
   @ 4, 2 SAY OemToAnsi( "Endere‡o:" ) OF oDlg UPDATE  FONT oFnt ;
          COLORS CLR_HBLUE, CLR_WHITE

   @ 65, 50 GET oGet3 VAR mpara_rua OF oDlg PIXEL SIZE 185, 12 PICTURE "@!" ;
            UPDATE FONT oFnt COLORS CLR_BLACK, CLR_WHITE                    ;
            VALID VALIDA_BOTAO( mpara_rua, oBusca )

   @ 7.00, 13 BUTTON oBusca PROMPT "&Buscar"  OF oDlg ;
              WHEN( lLigaBotao )                      ;
              ACTION ( lSaida := .T., nKey := VK_RETURN, oDlg:End() ) CANCEL

   oBusca:cToolTip := "Pesquisar a Rua no Google Maps"

   @ 7.00, 21 BUTTON oSaida PROMPT "&Saida"  OF oDlg ;
              ACTION ( lSaida := .T., nKey := VK_ESCAPE, oDlg:End() ) CANCEL

   oSaida:cToolTip := "Saida - Exit - Cancelar"

   SET FONT OF oBusca  TO oFont
   SET FONT OF oSaida  TO oFont

   //read

   ACTIVATE DIALOG oDlg CENTERED ;
            VALID( lSaida )

   oFnt:End()
   oFont:End()

   Set( _SET_INSERT, ! Set( _SET_INSERT ) )

   DO CASE
   CASE nKey == VK_ESCAPE .OR. GETKEYSTATE( VK_ESCAPE )

      lSaida := .F.
      lLigaBotao := .F.

      RETURN NIL

   ENDCASE

   // By Billy1943 - Forum PC Toledo. Ideia Original. Agradecimentos.
   mpara_uf  := alltrim( mpara_uf  )
   mpara_cid := alltrim( mpara_cid )
   mpara_rua := alltrim( mpara_rua )
   msearch   := mpara_rua + " " + mpara_cid + " " + mpara_uf

   DEFINE WINDOW oWnd TITLE "FiveWin ActiveX Support"

   oActiveX = TActiveX():New( oWnd, "Shell.Explorer" )

   oActivex:Silent := .T.  // Para Evitar: Erro de Script na Pagina.

   oWnd:oClient = oActiveX // To fill the entire window surface

   // funciona assim quebra se clicar na imagem
   /*
   oActiveX:Navigate( "https://google.com.br/search?q=" + ;
                       ALLTRIM( msearch ) + "&oq=" +      ;
                       ALLTRIM( msearch ) + "&aqs=chrome" )
   */

   // Erro de Script na Pagina?
   // https://www.google.com.br/maps/place
   // gerando erro de navegador antigo. ?????
   //oActiveX:Navigate( "https://www.google.com.br/maps/place/" + msearch  )

   oActiveX:Navigate( "https://www.google.com.br/maps/place/" + ALLTRIM(msearch)  )

   //oActiveX:bOnEvent = { | event, aParams, pParams | cEvents += EventInfo( event, aParams, pParams, oActiveX ) }

   ACTIVATE WINDOW oWnd MAXIMIZED  /*  ;  // Nao quero editar nada.
            VALID ( MemoEdit( cEvents ), .t. ) */

RETURN NIL

FUNCTION VALIDA_GET1( cmpara_uf )

   IF GETASYNCKEY( VK_UP ) // Para nao perder o foco do dialgo
      RETURN( .F. )
   ENDIF

   IF EMPTY( cmpara_uf )

      MsgInfo( OemToAnsi( "OPERA€ÇO INVµLIDA!             " )+CRLF+ ;
               OemToAnsi( "DIGITIE O NOME DA UF...        " )+CRLF+ ;
               OemToAnsi( "TECLE <ENTER> PARA CONTINUAR..." ),      ;
               OemToAnsi( "OPERA€ÇO INVµLIDA!             " ) )

      lLigaBotao := .F.

      RETURN( .F. )

   ENDIF

RETURN( .T. )

FUNCTION VALIDA_GET2( cmpara_cid )

   IF EMPTY( cmpara_cid )

      MsgInfo( OemToAnsi( "OPERA€ÇO INVµLIDA!             " )+CRLF+ ;
               OemToAnsi( "DIGITIE O NOME DA CIDADE...    " )+CRLF+ ;
               OemToAnsi( "TECLE <ENTER> PARA CONTINUAR..." ),      ;
               OemToAnsi( "OPERA€ÇO INVµLIDA!             " ) )

      lLigaBotao := .F.

      RETURN( .F. )

   ENDIF

RETURN( .T. )

FUNCTION VALIDA_BOTAO( cmpara_rua, oBusca )

   IF EMPTY( cmpara_rua )

      MsgInfo( OemToAnsi( "OPERA€ÇO INVµLIDA!             " )+CRLF+ ;
               OemToAnsi( "DIGITIE O NOME DA RUA...       " )+CRLF+ ;
               OemToAnsi( "TECLE <ENTER> PARA CONTINUAR..." ),      ;
               OemToAnsi( "OPERA€ÇO INVµLIDA!             " ) )

      lLigaBotao := .F.

      RETURN( .F. )

   ENDIF

   // TUDO NORMAL, VAI BUSCAR NO GOOGLE

   lLigaBotao := .T.

   oBusca:Enable()
   oBusca:Refresh()

RETURN( .T. )

FUNCTION EventInfo( event, aParams, pParams, oActiveX )

   local cMsg := "Event: " + cValToChar( event ) + CRLF
   local n

   cMsg += "Params: " + CRLF

   for n = 1 to Len( aParams )
   cMsg += cValToChar( aParams[ n ] ) + CRLF
   next

   if event == "BeforeNavigate2"
   // MsgInfo( aParams[ 2 ] )
   // SetEventParam( pParams, 7, .t. ) // Comment this to allow navigation
   endif

RETURN cMsg + CRLF

// END OF PROGRAM
 

Re: Fivewin con Google Maps

Posted: Mon Jan 18, 2016 1:45 pm
by cmsoft
Este codigo me funciona, probalo:

Code: Select all

#include "FiveWin.ch"

static cPais:="",cCiudad:="",cCalle:=""
static oGet1,oGet2,oGet3,oBtn1,oBtn2,nSeg:=0,oWnd

FUNCTION Mapas()
LOCAL oForm
cPais  :=LEFT("ARGENTINA"+SPACE(255),255)
cCiudad:=LEFT("MERCEDES"+SPACE(255),255)
cCalle :=LEFT("29 575"+SPACE(255),255)
DEFINE DIALOG oForm TITLE "Localizacion Google maps" FROM 05,15 TO 40,95 
  oForm:lHelpIcon := .f.
  @ 07, 05 SAY "Calle:"   OF oForm PIXEL SIZE 50,20 RIGHT
  @ 22, 05 SAY "Ciudad:"  OF oForm PIXEL SIZE 50,20 RIGHT
  @ 37, 05 SAY "Pais:"    OF oForm PIXEL SIZE 50,20 RIGHT
  @ 05, 65 GET oGet1 VAR cCalle  PICTURE "@S30"  OF oForm PIXEL 
  @ 20, 65 GET oGet2 VAR cCiudad PICTURE "@S30"  OF oForm PIXEL
  @ 35, 65 GET oGet3 VAR cPais   PICTURE "@S30"  OF oForm PIXEL
  @ 45, 00 ACTIVEX oWnd OF oForm PROGID "Shell.Explorer.2"
  @ 22,105 BUTTON oBtn1 OF oForm ACTION VerMapa(oWnd) PIXEL
ACTIVATE DIALOG oForm CENTERED ON INIT VerMapa(oWnd)
RETURN nil

STATIC FUNCTION VerMapa( oActivex)
LOCAL cHtml, oWnd

        cHtml :=[ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> ] +CRLF
        cHtml +=[ <html xmlns="http://www.w3.org/1999/xhtml"> ] + CRLF
        cHtml +=[ <head> ]+CRLF
        cHtml +=[<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> ]+CRLF
        cHtml +=[<title> </title> ]+CRLF
        cHtml +=[<script src="http://maps.google.com/maps?file=api&v=2.x&key=ABQIAAAAtOjLpIVcO8im8KJFR8pcMhQjskl1-YgiA_BGX2yRrf7htVrbmBTWZt39_v1rJ4xxwZZCEomegYBo1w" type="text/javascript"></script>]+CRLF
        cHtml +=[<script type="text/javascript">]+CRLF
        cHtml +=[var map = null;]+CRLF
        cHtml +=[var geocoder = null;]+CRLF
        cHtml +=[var coords = null;]+CRLF
        cHtml +=[function initialize() {]+CRLF
        cHtml +=[if (GBrowserIsCompatible()) {]+CRLF
        cHtml +=[map = new GMap2(document.getElementById("map_canvas"));]+CRLF
        cHtml +=[map.addControl(new GLargeMapControl());]+CRLF
        cHtml +=[map.addControl(new GMapTypeControl());]+CRLF
        cHtml +=[map.addControl(new GOverviewMapControl());]+CRLF
        cHtml +=[geocoder = new GClientGeocoder();]+CRLF
        cHtml +=[}]+CRLF
        cHtml +=[}]+CRLF
        cHtml +=[function showAddress(address, cAddressName) {]+CRLF
        cHtml +=[if (geocoder) {]+CRLF
        cHtml +=[geocoder.getLatLng(]+CRLF
        cHtml +=[address,]+CRLF
        cHtml +=[function(point) {]+CRLF
        cHtml +=[if (!point) {]+CRLF
        cHtml +="showAddress2('"+ALLTRIM(cCiudad)+"');"+CRLF
        cHtml +=[} else {                                                      ]+CRLF
        cHtml +=[map.setCenter(point, 15);                                  ]+CRLF
        cHtml +=[var marker = new GMarker(point);                            ]+CRLF
        cHtml +=[map.addOverlay(marker);                                    ]+CRLF
        cHtml +=[coords = marker.getPoint();                                ]+CRLF
        cHtml +=[var curl = cAddressName + "<p>" + coords.toUrlValue(6) + "</p>" ]+CRLF
        cHtml +=[var button = '<input type="button" value="Imprimir" onClick="window.print()"/>;' ]+CRLF
        cHtml +=[curl = curl + button ]+CRLF
        cHtml +=[}                          ]+CRLF                                  
        cHtml +=[}                                ]+CRLF                              
        cHtml +=[);                                     ]+CRLF                           
        cHtml +=[}                                                                  ]+CRLF
        cHtml +=[}                                                                    ]+CRLF
        cHtml +=[function showAddress2(address) {        ]+CRLF
        cHtml +=[if (geocoder) {                               ]+CRLF                     
        cHtml +=[geocoder.getLatLng(                                 ]+CRLF             
        cHtml +=[address,                                                  ]+CRLF      
        cHtml +=[function(point) {                                              ]+CRLF
        cHtml +=[if (!point) {                                                ]+CRLF
        cHtml +=[alert(address + " no encontrado");                          ]+CRLF
        cHtml +=[} else {                                                      ]+CRLF
        cHtml +=[map.setCenter(point, 15);                                  ]+CRLF
        cHtml +=[var marker = new GMarker(point);                            ]+CRLF
        cHtml +=[map.addOverlay(marker);                                    ]+CRLF
        cHtml +=[marker.openInfoWindowHtml(address);                        ]+CRLF
        cHtml +=[}                                                            ]+CRLF
        cHtml +=[}                                                              ]+CRLF
        cHtml +=[);                                                               ]+CRLF
        cHtml +=[}                                                                  ]+CRLF
        cHtml +=[}                                                                    ]+CRLF
        cHtml +=[</script>                                                            ]+CRLF
        cHtml +=[</head>                                                                ]+CRLF
        cHtml +=[<body onload="initialize();]
        cHtml +=" showAddress('"+ALLTRIM(cCalle)+", "+ALLTRIM(cCiudad)+"  "+ALLTRIM(cPais)+"', '"+ALLTRIM(cCalle)+", "+ALLTRIM(cCiudad)+"  "+ALLTRIM(cPais)+"');"
        cHtml +=[" onunload="GUnload()"]+CRLF
        cHtml +=[<div id="map_canvas" style="width: 597px; height: 376px"></div> ]+CRLF
        cHtml +=[</body>                                                               ]+CRLF 
        cHtml +=[</html>]+CRLF

        MemoWrit("mihtml.htm",chtml)


   *DEFINE WINDOW oWnd TITLE "FiveWin ActiveX Support"

   *oActiveX = TActiveX():New( oWnd, "Shell.Explorer.2" )

   *oWnd:oClient = oActiveX // To fill the entire window surface

   oActiveX&#058;Do("Navigate2",(HB_CurDrive() + ":\"+CurDir()+"\MiHtml.htm"))

   *ACTIVATE WINDOW oWnd
RETURN NIL


Re: Fivewin con Google Maps

Posted: Mon Jan 18, 2016 5:10 pm
by cnavarro
CmSoft, tu codigo me da el siguiente error, cual puede ser el motivo?
Aparece bien, pero al cabo de unos segundos cuando termina de cargar aparece este mensaje

Image

Re: Fivewin con Google Maps

Posted: Mon Jan 18, 2016 5:42 pm
by leandro
cmsoft buenas tardes muchas gracias por compartir el código

Intente compilar pero me arroja el siguiente error:

Code: Select all

xHarbour 1.2.3 Intl. (SimpLex) (Build 20150419)
Copyright 1999-2015, http://www.xharbour.org http://www.harbour-project.org/
Compiling 'Noname.prg'...
1 error 
No code generated
Noname.prg(102) Error E0030  Syntax error: "syntax error at '058'"
 
El error me sale en la linea

Code: Select all

 oActiveX&#058;Do("Navigate2",(HB_CurDrive() + ":\"+CurDir()+"\MiHtml.htm"))
De antemano gracias

Re: Fivewin con Google Maps

Posted: Mon Jan 18, 2016 5:53 pm
by cnavarro
Leandro, sustituye
&#058;
por
:

Re: Fivewin con Google Maps

Posted: Mon Jan 18, 2016 7:27 pm
by karinha
un poco lento, pero funciona

Image

Gracias, saludos.

Re: Fivewin con Google Maps

Posted: Tue Jan 19, 2016 2:31 am
by cmsoft
Hola compañeros:
Tal cual lo dice karinha es lento el codigo, y como dice Cristobal, tambien me da (no siempre, pero me da) el error que muestras.
Habría que intentar de correrlo con Chrome en lugar de con Explorer.
Cualquier sugerencia, compartan...

Re: Fivewin con Google Maps

Posted: Tue Jan 19, 2016 7:11 am
by cnavarro
cmsoft wrote:Hola compañeros:
Tal cual lo dice karinha es lento el codigo, y como dice Cristobal, tambien me da (no siempre, pero me da) el error que muestras.
Habría que intentar de correrlo con Chrome en lugar de con Explorer.
Cualquier sugerencia, compartan...
Quizás estoy pueda ayudar para evitar el error

Code: Select all


   oActiveX&#058;Silent := .T.     // Añadir
   oActiveX&#058;Do("Navigate2",( HB_CurDrive() + ":\" + CurDir() + "\MiHtml.htm" ))


Re: Fivewin con Google Maps

Posted: Tue Jan 19, 2016 11:15 am
by cmsoft
Efectivamente Cristobal! Ya no da el error!!
Muchas gracias! Faltaría ver si se puede solucionar el tema de la lentitud con la que muestra el mapa...

Re: Fivewin con Google Maps (SOLUCIONADO)

Posted: Tue Jan 19, 2016 11:38 am
by Loren
Compañeros, buenas tardes:

Resuelto el tema y me funciona rápido y perfecto. Al menos con las pruebas que he hecho!!

Code: Select all

...
redefine get oget[1] var pdireccion id 4001 of oDlg
redefine get oget[2] var ppoblacion id 4002 of oDlg
redefine button obutton id 4003 of odlg action google(pdireccion,ppoblacion)
...


funct google(pdireccion,ppoblacion)
  Local cdire, cpobla, cweb:='https://www.google.es/maps/search/'  && importante que sea  "SEARCH" NO "PLACE"
  if empty(pdireccion) ; msgstop('Imposible mostrar un mapa porque no tecleó ninguna dirección.','') ; return ; endif
  if empty(ppoblacion) ; msgalert('Si teclea una población, la búsqueda será más efectiva.','') ; endif
  cdire = upper(pdireccion)
  cdire = StrTran( ALLTRIM(cdire), '-' ,'')
  cdire = StrTran( ALLTRIM(cdire), 'C/','')
  cdire = StrTran( ALLTRIM(cdire), '/' ,'')
  cdire = StrTran( ALLTRIM(cdire), 'Nº','')
  cdire = StrTran( ALLTRIM(cdire), '  ',' ')
  cdire = StrTran( ALLTRIM(cdire), ' ', '+')
  cpobla= upper(ppoblacion)
  cpobla= StrTran( ALLTRIM(ppoblacion), '-', '' )
  cpobla= StrTran( ALLTRIM(ppoblacion), ' ', '+')
  ShellExecute(GetActiveWindow(),Nil,iif(!empty(cdire),cweb+alltrim(cdire)+'+'+alltrim(cpobla),''),",",1) 
return
 
Gracias. Un saludo.
LORENZO.

Re: Fivewin con Google Maps (SOLUCIONADO)

Posted: Tue Jan 19, 2016 2:59 pm
by ACC69
Loren wrote:Compañeros, buenas tardes:

Resuelto el tema y me funciona rápido y perfecto. Al menos con las pruebas que he hecho!!

Code: Select all

...
redefine get oget[1] var pdireccion id 4001 of oDlg
redefine get oget[2] var ppoblacion id 4002 of oDlg
redefine button obutton id 4003 of odlg action google(pdireccion,ppoblacion)
...


funct google(pdireccion,ppoblacion)
  Local cdire, cpobla, cweb:='https://www.google.es/maps/search/'  && importante que sea  "SEARCH" NO "PLACE"
  if empty(pdireccion) ; msgstop('Imposible mostrar un mapa porque no tecleó ninguna dirección.','') ; return ; endif
  if empty(ppoblacion) ; msgalert('Si teclea una población, la búsqueda será más efectiva.','') ; endif
  cdire = upper(pdireccion)
  cdire = StrTran( ALLTRIM(cdire), '-' ,'')
  cdire = StrTran( ALLTRIM(cdire), 'C/','')
  cdire = StrTran( ALLTRIM(cdire), '/' ,'')
  cdire = StrTran( ALLTRIM(cdire), 'Nº','')
  cdire = StrTran( ALLTRIM(cdire), '  ',' ')
  cdire = StrTran( ALLTRIM(cdire), ' ', '+')
  cpobla= upper(ppoblacion)
  cpobla= StrTran( ALLTRIM(ppoblacion), '-', '' )
  cpobla= StrTran( ALLTRIM(ppoblacion), ' ', '+')
  ShellExecute(GetActiveWindow(),Nil,iif(!empty(cdire),cweb+alltrim(cdire)+'+'+alltrim(cpobla),''),",",1) 
return
 
Gracias. Un saludo.
LORENZO.

Hola buenos dias a todos,les envio cordial saludos.

Referente al tema de google maps, el Ing. Alfredo Arteaga tiene la rutina mejorada de google maps,sera que nos podra compartir su codigo de google maps?

Esta es la imagen:

Image

Saludos y buen dia.!

Atte: Adrian C. C.
acc69@hotmail.com

Re: Fivewin con Google Maps

Posted: Tue Jan 03, 2017 9:10 pm
by Silvio.Falconi
CAN YOU PUBBLISH THE ALL CODE RUN OK PLEASE

BECAUSE HERE NOT RUN ...

THANKS