Jump to content
Fivewin Brasil

Quando digitar a cidade Marcar os clientes ativos Google maps


Marca

Recommended Posts

 

Aqui tem algo parecido com o q. quero sendo q. esta configurado para Espanha e não sei configurar para o Brasil

 

 

http://forums.fivetechsupport.com/viewtopic.php?f=3&t=33729&p=199601&hilit=google+maps#p199601

 

@Marca eu peguei essa rotina que vc postou ai e testei,  mudando apenas os endereços no Array aDatas e funciona... não sei se tem que configurar algo não...

coloquei assim e deu certo!!! 

                       AAdd( aDatas, VerMapa2( "", "Rua Marechal Juarez Távora", "84", "Medicina", "MG", "Brasil" ) )
                       AAdd( aDatas, VerMapa2( "", "Rua Delfim Moreira", "280", "São Vicente", "MG", "Brasil" ) )
                       AAdd( aDatas, VerMapa2( "", "Rua Marechal Juarez Távora", "294", "Medicina", "MG", "Brasil" ) )

 

E tem esse aqui que peguei aqui no forum mesmo, faz um teste e vê se resolve...

Function VerRotaVisitadas(aDd)  // aDd = { {Nome, Endereco, Bairro, Cidade, Estado} }
Local cHtml:="", oOle, x1:=0, nD1 := 1

     *oOle:= CreateObject("InternetExplorer.Application")
     *oOle:Visible    := .t.   // Apresenta o Browser
     *oOle:ToolBar    := .f.   // Desativa a barra de ferramentas
     *oOle:StatusBar  := .f.   // Desativa a barra de status
     *oOle:MenuBar    := .f.   // desativa a barra de menu

        cHtml+='<head>'+CRLF
        cHtml+='<title>Mapeamento dos Clientes</title>'+CRLF
        cHtml+='<style type="text/css">'+CRLF
        cHtml+='#mapa{width:1200px;'+CRLF
        cHtml+='height:1000px}'+CRLF
        cHtml+='</style>'+CRLF
        cHtml+='<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>'+CRLF
        cHtml+='<script type="text/javascript">'+CRLF
        cHtml+='var map = null;'+CRLF
        cHtml+='function carregar(){'+CRLF
        cHtml+='var latlng = new google.maps.LatLng(-3.787522,-38.518066);'+CRLF
        cHtml+='var myOptions = {'+CRLF
        cHtml+='zoom: 14,'+CRLF
        cHtml+='center: latlng,'+CRLF
        cHtml+='mapTypeId: google.maps.MapTypeId.ROADMAP};'+CRLF
        cHtml+='map = new google.maps.Map(document.getElementById("mapa"), myOptions);'+CRLF
        *
        For nD1 := 1 To Len(aDd)
           cNome_Google         := aDd[nD1,1]
              cEndereco_Google := aDd[nD1,2]
              cBairro_Google     := aDd[nD1,3]
           cCidade_Google     := aDd[nD1,4]
              cEstado_Google     := aDd[nD1,5]
              x1++
           fBus    := "BUSA.JPG"  
           cHtml    += ' '+CRLF
           cHtml    += 'var endereco'+Alltrim(Str(x1))+'="'+Alltrim(cEndereco_Google)+' - '+Alltrim(cBairro_Google)+' - '+Alltrim(cCidade_Google)+' - '+AllTrim(cEstado_Google)+'";'+CRLF
           cHtml    += 'geocoder = new google.maps.Geocoder();'+CRLF
           cHtml    += 'geocoder.geocode({"address":endereco'+Alltrim(str(x1))+'}, function(results, status){ if( status = google.maps.GeocoderStatus.OK){ latlng = results[0].geometry.location;'+CRLF
           cHtml    += 'markerInicio'+Alltrim(Str(x1))+' = new google.maps.Marker({position: latlng,map: map, title:"'+Alltrim(cNome_Google)+'", icon: "'+fBus+'"});'+CRLF
           cHtml    += [var infowindow = new google.maps.InfoWindow({ content: '<strong>]+Alltrim(cNome_google)+[</strong><br>]+Alltrim(cEndereco_Google)+[, ]+Alltrim(cBairro_Google)+[ ]+Alltrim(cCidade_Google)+[ ]+Alltrim(cEstado_Google)+[<BR>]+['});]+CRLF
           cHtml    += 'google.maps.event.addListener(markerInicio'+Alltrim(Str(x1))+', "click", function(event) { infowindow.open(map,markerInicio'+Alltrim(Str(x1))+');});'+CRLF
           cHtml    += 'map.setCenter(latlng); } });'+CRLF
           cHtml    += ' '+CRLF
           *
        Next nD1
        *
        cHtml+='}'+CRLF
        cHtml+='</script>'+CRLF
        cHtml+='</head>'+CRLF
        cHtml+='<body onload="carregar()">'+CRLF
        cHtml+='<div id="mapa"></div>'+CRLF
        cHtml+='</body>'+CRLF
        cHtml+='</html>'+CRLF

         MemoWrit("visitarota.html",chtml)  // uRegPath = "c:\test"

             ShellExecute(GetActiveWindow(),"open",'visitarota.html')
 
        *oOle:Navigate2("visitarota.htm")

        *hWnd:=oOle:hWnd
        *BringWindowToTop(hWnd)

Return nil

Link to comment
Share on other sites

Marca,

Eu tinha funcionando um projeto com o GMaps mas depois da última atualização deles parou de funcionar e eu mudei para utilizar o google earth que é muito mais simples.

Basta você gerar um arquivo xml com a extensão de kml com os dados dos clientes e abrir o Ggl Earth com o arquivo e ele exibe sem problemas, sem contar que ele traz muito mais recursos de vc poder inibir/exibir um ou outro cliente e outros,

Quanto às delimitações tenho aqui em algum lugar alguns arquivos. Faz tempo que não uso o google earth ou gmaps com o fivewin. Hj tenho uma solução de geomarketing toda feita na windev.

Segue o código da geração do arquivo kml

   //
   // cria arquivo xml com extenção kml
   //
   cARQ     := GETPVPROFSTRING("EMPRESA"+xEMPR(),"DIRGEO","",cINIFILE) + "doc.kml"
   nIDPRN := FCREATE(cARQ)
   //
   // monta headerdo xml
   //
   cTXT := [<?xml version="1.0" encoding="UTF-8"?>]
   cTXT += [<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">]
   cTXT += [<Folder>]
   cTXT += [<name>]+"Clientes " + DTOC(dDATAI) + " a " + DTOC(dDATAF) + "  Tp Fat.:" + cTIPOFT + [</name>] + CRLF
   cTXT += [<Style id="branco">]
   cTXT += [<IconStyle>]
   cTXT += [<Icon>]
   cTXT += [<href>http://maps.google.com/mapfiles/kml/paddle/wht-stars.png</href>]
   cTXT += [</Icon>]
   cTXT += [</IconStyle>]
   cTXT += [</Style>] + CRLF
   cTXT += [<Style id="verde">]
   cTXT += [<IconStyle>]
   cTXT += [<Icon>]
   cTXT += [<href>http://maps.google.com/mapfiles/kml/paddle/grn-stars.png</href>]
   cTXT += [</Icon>]
   cTXT += [</IconStyle>]
   cTXT += [</Style>] + CRLF
   cTXT += [<Style id="azul">]
   cTXT += [<IconStyle>]
   cTXT += [<Icon>]
   cTXT += [<href>http://maps.google.com/mapfiles/kml/paddle/blu-stars.png</href>]
   cTXT += [</Icon>]
   cTXT += [</IconStyle>]
   cTXT += [</Style>] + CRLF
   cTXT += [<Style id="amarelo">]
   cTXT += [<IconStyle>]
   cTXT += [<Icon>]
   cTXT += [<href>http://maps.google.com/mapfiles/kml/paddle/ylw-stars.png</href>]
   cTXT += [</Icon>]
   cTXT += [</IconStyle>]
   cTXT += [</Style>] + CRLF
   cTXT += [<Style id="vermelho">]
   cTXT += [<IconStyle>]
   cTXT += [<Icon>]
   cTXT += [<href>http://maps.google.com/mapfiles/kml/paddle/red-stars.png</href>]
   cTXT += [</Icon>]
   cTXT += [</IconStyle>]
   cTXT += [</Style>] + CRLF
   cTXT += [<Style id="inativo">]
   cTXT += [<IconStyle>]
   cTXT += [<Icon>]
   cTXT += [<href>http://maps.google.com/mapfiles/kml/shapes/forbidden.png</href>]
   cTXT += [</Icon>]
   cTXT += [</IconStyle>]
   cTXT += [</Style>] + CRLF
   FWRITE(nIDPRN,cTXT,LEN(cTXT))
   //
   // insere os marcadores
   //
   DA3->(DBGOTOP())
   DO WHILE DA3->(!EOF())
      IF !EMPTY(DA3->DA3_ENDER)
         cTXT := [<Placemark id="] + DA3->DA3_CODIGO + [">]
         cTXT += [<name>] + ALLTRIM(DA3->DA3_RAZAO) + [</name>]
         cTXT += [<description>]
         cTXT += "Vendedor : " + DA3->DA3_CODIGO + " - " + TIRAACENTO(ALLTRIM(DA3->DA3_RAZAO)) + CRLF + TIRAACENTO(ALLTRIM(DA3->DA3_NFANT)) + CRLF
         cTXT += [</description>]
         cTXT += [<address>] + ALLTRIM(DA3->DA3_ENDER) + " - " + ALLTRIM(DA1->DA1_BAIRRO) + " - " + ALLTRIM(DA1->DA1_MUNIC) + [</address>]
         cTXT += [<styleUrl>#azul</styleUrl>]
         cTXT += [</Placemark>] + CRLF
         FWRITE(nIDPRN,cTXT,LEN(cTXT))
      ENDIF
      *
      DA3->(DBSKIP())
   ENDDO
   // 
   // finaliza arquivo
   // 
   cTXT := [</Folder>] + CRLF
   cTXT += [</kml>]
   FWRITE(nIDPRN,cTXT,LEN(cTXT))
   FCLOSE(nIDPRN)
   // 
   // chama google earth com o arquivo gerado
   // 
   WINEXEC("C:\Program Files (x86)\Google\Google Earth\client\googleearth.exe " + cARQ)

Eu já vi algo de abrir este arquivo kml no gmaps, mas nunca tentei.

Espero ter ajudado não só a você mas a quem mais precisar.

Abraços

Alexandre Zilves 

Link to comment
Share on other sites

 

@Marca eu peguei essa rotina que vc postou ai e testei,  mudando apenas os endereços no Array aDatas e funciona... não sei se tem que configurar algo não...

coloquei assim e deu certo!!! 

                       AAdd( aDatas, VerMapa2( "", "Rua Marechal Juarez Távora", "84", "Medicina", "MG", "Brasil" ) )
                       AAdd( aDatas, VerMapa2( "", "Rua Delfim Moreira", "280", "São Vicente", "MG", "Brasil" ) )
                       AAdd( aDatas, VerMapa2( "", "Rua Marechal Juarez Távora", "294", "Medicina", "MG", "Brasil" ) )

 

E tem esse aqui que peguei aqui no forum mesmo, faz um teste e vê se resolve...

Function VerRotaVisitadas(aDd)  // aDd = { {Nome, Endereco, Bairro, Cidade, Estado} }
Local cHtml:="", oOle, x1:=0, nD1 := 1

     *oOle:= CreateObject("InternetExplorer.Application")
     *oOle:Visible    := .t.   // Apresenta o Browser
     *oOle:ToolBar    := .f.   // Desativa a barra de ferramentas
     *oOle:StatusBar  := .f.   // Desativa a barra de status
     *oOle:MenuBar    := .f.   // desativa a barra de menu

        cHtml+='<head>'+CRLF
        cHtml+='<title>Mapeamento dos Clientes</title>'+CRLF
        cHtml+='<style type="text/css">'+CRLF
        cHtml+='#mapa{width:1200px;'+CRLF
        cHtml+='height:1000px}'+CRLF
        cHtml+='</style>'+CRLF
        cHtml+='<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>'+CRLF
        cHtml+='<script type="text/javascript">'+CRLF
        cHtml+='var map = null;'+CRLF
        cHtml+='function carregar(){'+CRLF
        cHtml+='var latlng = new google.maps.LatLng(-3.787522,-38.518066);'+CRLF
        cHtml+='var myOptions = {'+CRLF
        cHtml+='zoom: 14,'+CRLF
        cHtml+='center: latlng,'+CRLF
        cHtml+='mapTypeId: google.maps.MapTypeId.ROADMAP};'+CRLF
        cHtml+='map = new google.maps.Map(document.getElementById("mapa"), myOptions);'+CRLF
        *
        For nD1 := 1 To Len(aDd)
           cNome_Google         := aDd[nD1,1]
              cEndereco_Google := aDd[nD1,2]
              cBairro_Google     := aDd[nD1,3]
           cCidade_Google     := aDd[nD1,4]
              cEstado_Google     := aDd[nD1,5]
              x1++
           fBus    := "BUSA.JPG"  
           cHtml    += ' '+CRLF
           cHtml    += 'var endereco'+Alltrim(Str(x1))+'="'+Alltrim(cEndereco_Google)+' - '+Alltrim(cBairro_Google)+' - '+Alltrim(cCidade_Google)+' - '+AllTrim(cEstado_Google)+'";'+CRLF
           cHtml    += 'geocoder = new google.maps.Geocoder();'+CRLF
           cHtml    += 'geocoder.geocode({"address":endereco'+Alltrim(str(x1))+'}, function(results, status){ if( status = google.maps.GeocoderStatus.OK){ latlng = results[0].geometry.location;'+CRLF
           cHtml    += 'markerInicio'+Alltrim(Str(x1))+' = new google.maps.Marker({position: latlng,map: map, title:"'+Alltrim(cNome_Google)+'", icon: "'+fBus+'"});'+CRLF
           cHtml    += [var infowindow = new google.maps.InfoWindow({ content: '<strong>]+Alltrim(cNome_google)+[</strong><br>]+Alltrim(cEndereco_Google)+[, ]+Alltrim(cBairro_Google)+[ ]+Alltrim(cCidade_Google)+[ ]+Alltrim(cEstado_Google)+[<BR>]+['});]+CRLF
           cHtml    += 'google.maps.event.addListener(markerInicio'+Alltrim(Str(x1))+', "click", function(event) { infowindow.open(map,markerInicio'+Alltrim(Str(x1))+');});'+CRLF
           cHtml    += 'map.setCenter(latlng); } });'+CRLF
           cHtml    += ' '+CRLF
           *
        Next nD1
        *
        cHtml+='}'+CRLF
        cHtml+='</script>'+CRLF
        cHtml+='</head>'+CRLF
        cHtml+='<body onload="carregar()">'+CRLF
        cHtml+='<div id="mapa"></div>'+CRLF
        cHtml+='</body>'+CRLF
        cHtml+='</html>'+CRLF

         MemoWrit("visitarota.html",chtml)  // uRegPath = "c:\test"

             ShellExecute(GetActiveWindow(),"open",'visitarota.html')
 
        *oOle:Navigate2("visitarota.htm")

        *hWnd:=oOle:hWnd
        *BringWindowToTop(hWnd)

Return nil

Theotokos

Qual  das funções  VerMapa2() vc utilizou ?

No demo lá tem varias

 

Link to comment
Share on other sites

 

Você pode postar ela aqui ?

 

#include "FiveWin.ch"

Static cUrl     := ""

Function TstMapa()

   Local aDatas := {}
   SET 3DLOOK OFF
   //                      cPostal_Code, cStreet, cNumber, cLocality, cState, cNation )
                       AAdd( aDatas, VerMapa2( "37500", "Rua Marechal Juarez Távora", "84", "Medicina", "MG", "Brasil" ) )
                       AAdd( aDatas, VerMapa2( "37502", "Rua Delfim Moreira", "280", "São Vicente", "MG", "Brasil" ) )
                       AAdd( aDatas, VerMapa2( "37500", "Rua Marechal Juarez Távora", "294", "Medicina", "MG", "Brasil" ) )
   
   ViewLeafLet( aDatas )

Return nil

//----------------------------------------------------------------------------//

Function VerMapa2( cPostal_Code, cStreet, cNumber, cLocality, cState, cNation )
   
   Local cWeb  := "http://maps.google.es/maps/place/"
   local cMap
   local cRet  := ""
   local oOle
   local nPos1
   local nPos2
   local aCoor := { 0, 0, 0 }
   cPostal_Code := StrTran( AllTrim( cPostal_Code ), ' ', '+' )
   cStreet      := StrTran( AllTrim( cStreet ), ' ', '+' )
   cNumber      := StrTran( AllTrim( cNumber ), ' ', '+' )
   cLocality    := StrTran( AllTrim( cLocality ), ' ', '+' )
   cState       := StrTran( AllTrim( cState ), ' ', '+' )
   cNation      := StrTran( AllTrim( cNation ), ' ', '+' )
   cMap     :=  AllTrim( cPostal_Code ) + "+" + AllTrim( cStreet ) + "+" + ;
                AllTrim( cNumber ) + "+" + AllTrim( cLocality ) + "+" + ;
                AllTrim( cState ) + "+" + AllTrim( cNation )
   oOle  := CreateObject("Winhttp.WinHttpRequest.5.1")
   oOle:Open( "GET", cWeb + AllTrim( cMap ), .F. )
   oOle:Send()
   cURL := oOle:ResponseText

   nPos1  := At( "cacheResponse([[[", Left( cURL, 2048 ) )
   if !Empty( nPos1 )
      cRet   := Substr( Left( cURL, 1024 ), nPos1 + 17, 2048 - nPos1 )
      nPos2  := At( "]", cRet )
      if !Empty( nPos2 )
         cRet   := Left( cRet, nPos2 - 1 )
         aCoor  := hb_ATokens( cRet, "," )
      endif
   endif
   //XBrowse( aCoor )

Return aCoor

//----------------------------------------------------------------------------//

Function ViewLeafLet(aData)
   
   local cMapFile   := "D:\GMaps.htm"
   local cHtmlContent1
   local cHtmlContent2
   local cHtmlContent3
   local cInitMap   := "   var mymap = L.map('mapid').setView( [ "
   local cAppendStr := "   L.polygon([" + CRLF
   local oOle
   local i

   TEXT INTO cHtmlContent1
   
   <!DOCTYPE html>
   <html>
   <head>
       <title>Quick Start - Leaflet</title>

       <meta charset="utf-8" />
       <meta name="viewport" content="width=device-width, initial-scale=1.0">
    
       <link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" />

       <link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.3/dist/leaflet.css" />
       <script src="https://unpkg.com/leaflet@1.0.3/dist/leaflet.js"></script>
   </head>
   <body>
      <div id="mapid" style="width: 700px; height: 560px;"></div>
      <script>
   ENDTEXT

   cInitMap  += aData[ 1 ][ 3 ] + ", " + aData[ 1 ][ 2 ] + " ], 13);" + CRLF

   TEXT INTO cHtmlContent2
    L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', {
        maxZoom: 18,
        attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
            '<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
            'Imagery © <a href="http://mapbox.com">Mapbox</a>',
        id: 'mapbox.streets'
    }).addTo(mymap);

   ENDTEXT

   For i := 1 to Len( aData )
      cAppendStr += Space( 4 ) + "[ " + aData[ i ][ 3 ] + ", " + ;
                    Ltrim( aData[ i ][ 2 ] )
      if i < Len( aData )
         cAppendStr += "]," + CRLF
      else
         cAppendStr += "]" + CRLF      
      endif
   Next
   cAppendStr += "]).addTo(mymap).bindPopup('I am a polygon.');" + CRLF + CRLF
    
   For i := 1 to Len( aData )
      cAppendStr += "L.marker( "
      cAppendStr += "[ " + aData[ i ][ 3 ] + ", " + ;
                    Ltrim( aData[ i ][ 2 ] ) + " ] )."
      cAppendStr += "addTo(mymap).bindPopup('<b>" + aData[ i ][1] + " !</b><br />Esta posicao.').openPopup();" + CRLF + CRLF
   Next
                              
   TEXT INTO cHtmlContent3
    var popup = L.popup();

    function onMapClick(e) {
        popup
            .setLatLng(e.latlng)
            .setContent("Position is: " + e.latlng.toString())
            .openOn(mymap);
    }

   mymap.on('click', onMapClick);

   </script>

   </body>
   </html>

   ENDTEXT

   MEMOWRIT( cMapFile, cHtmlContent1 + cInitMap + cHtmlContent2 + cAppendStr + cHtmlContent3 )

   oOle := CreateObject( "InternetExplorer.Application" )
   oOle:Width     := 750
   oOle:Height    := 650
   oOle:Visible   := .T.     // Displays the Browser
   oOle:ToolBar   := .F.     // Disables the toolbar
   oOle:StatusBar := .F.     // Disables status bar
   oOle:MenuBar   := .F.     // Disables the menu bar
   oOle:Navigate( cMapFile ) // Open the Webpage
   SysRefresh()
   
Return nil

//----------------------------------------------------------------------------//

Link to comment
Share on other sites

Olá pessoal... com relação a API do Google ela é FREE até X solicitações por dia... ou seja, eu implementei o código q varre a tabela de clientes e pelo endereço pega as coordenadas e depois armazena pra em uma próxima utilização não ter q pesquisar novamente e agilizar a montagem do mapa com os cliente marcadados, mas devido N testes começou em determinado momento não funcionar e ao debugar e olhar o conteúdo q retornava a mensagem era do Google q havia atingido o limite e pra acessar determinado URL deles onde cadastra o projeto/sistema nosso e tem os planos exemplo 4 dolares libera 10.000 acessos e por ai vai...

Minha dúvida é se adotando a solução do colega via Google Earth elimina essa limitação, pq se colocamos isso em nossos sistemas e os clientes começam a utilizar (não sei como eles controlam) mas dependendo o uso irá atingir o limite do Free, tudo bem q no outro dia libera (como hj já testei e esta liberado), mas o fato é q o limite da API do Google existe, alguém saberia responder?

Link to comment
Share on other sites

Fladimir, o limite é por key, vc precisa criar uma key na google pra cada cliente seu. 

Pessoal vou portar a função VerMapa2() aqui sim, só vi agora os pedidos, achei que havia enviado tudo.

Fiz uma solução de Geomarketing em Windev e como o Marca postou num grupo que eu tb faço parte, pediram lá que fizesse uma demo dele e gravaram ela. Ela se integra via txt, vc gera o txt e abre ele lá. Segue o endereço do vídeo. Só lembrando é um vídeo informal.

https://mega.nz/#!CQJ3gDTB!JOlBLfmjoSnyvDAOlXFAzrJix3Ms7eUmau116rh-rNE

Abraços a todos

Alexandre Zilves

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...