Jump to content
Fivewin Brasil

+1 google maps (distancia entre 2 pontos)


sistem

Recommended Posts


Local cHtml:="", oOle

If !IsInternet()

Msgalert("não conectado a internet.", "Aviso!")

Return nil

Endif

Ferase(uRegPath+"\tempgmapdist.html") // uRegPath:= "c:\test"

oOle:= CreateObject("InternetExplorer.Application")

oOle:Visible := .t.

oOle:ToolBar := .f.

oOle:StatusBar := .t.

oOle:MenuBar := .f.

cHtml := MemoRead(uRegPath+"\gmapdist.html")

cHtml := StrTran( cHtml, "ORIGEM", Alltrim(Empr->End_Empr)+", "+Alltrim(Empr->Nmr_Empr)+", "+Alltrim(Empr->Cid_Empr)+" - "+Empr->Est_Empr)

cHtml := StrTran( cHtml, "DESTINO", Alltrim(Clie->End_Clie)+", "+Alltrim(Clie->Nmr_Clie)+" "+Alltrim(Clie->Cid_Clie)+" - "+Clie->Est_Clie)

MemoWrit(uRegPath+"\tempgmapdist.html", chtml)

oOle:Navigate2(uRegPath+"\tempgmapdist.html")

hWnd:=oOle:hWnd

ShowWindow(hWnd, 3 ) //SW_MAXIMIZE=3 SW_NORMAL=1 SW_MINIMIZE=6

BringWindowToTop(hWnd)

Return nil

id=code>id=code>

arquivo html => gmapdist.html


var map, geocoder;

var mapDisplay, directionsService;

function initialize() {

var myOptions = {zoom: 15,mapTypeId: google.maps.MapTypeId.ROADMAP};

map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);

geocoder = new google.maps.Geocoder();

var enderDe = "ORIGEM";

var enderAte = "DESTINO";

geocoder.geocode( { 'address': enderAte, 'region' : 'BR'},trataLocs);

initializeDirections ();

calcRota (enderDe, enderAte);

}

function initializeDirections () {

directionsService = new google.maps.DirectionsService();

mapDisplay = new google.maps.DirectionsRenderer();

mapDisplay.setMap(map);

mapDisplay.setPanel(document.getElementById("panel")) }

function calcRota(endDe, endPara) {

var request = {

origin:endDe,

destination:endPara,

travelMode: google.maps.DirectionsTravelMode.DRIVING

};

directionsService.route(request, function(response, status) {

if (status == google.maps.DirectionsStatus.OK) {

mapDisplay.setDirections(response) }

}) }

function trataLocs (results, status) {

var elem = document.getElementById('msg');

if (status == google.maps.GeocoderStatus.OK) {

map.setCenter(results[0].geometry.location);

var marker = new google.maps.Marker({

map: map,

position: results[0].geometry.location });

if (results.length > 1) {

var i, txt = '';

elem.innerHTML = 'O endereço exato não foi localizado - há ' + results.length.toString() + ' resultados aproximados.

';

for (i = 0; i < results.length; i++) {

txt = txt + '

if (i == 0)

txt = txt + ' selected="selected"';

txt = txt + '>' + results.formatted_address + '

';

}

txt = txt + ''

elem.innerHTML = elem.innerHTML + txt;

}

} else

elem.innerHTML = 'Erro no tratamento do endereço :

' + status + '';

}

id=code>

id=code>

mapsdistw.png

Editado por - sistem on 27/11/2012 17:33:01

Link to comment
Share on other sites


Local cHtml:="", oOle

If !IsInternet()

Msgalert("não conectado a internet.", "Aviso!")

Return nil

Endif

Ferase(uRegPath+"\tempgmapdist.html") // uRegPath:= "c:\test"

oOle:= CreateObject("InternetExplorer.Application")

oOle:Visible := .t.

oOle:ToolBar := .f.

oOle:StatusBar := .t.

oOle:MenuBar := .f.

cHtml := MemoRead(uRegPath+"\gmapdist.html")

cHtml := StrTran( cHtml, "ORIGEM", Alltrim(Empr->End_Empr)+", "+Alltrim(Empr->Nmr_Empr)+", "+Alltrim(Empr->Cid_Empr)+" - "+Empr->Est_Empr)

cHtml := StrTran( cHtml, "DESTINO", Alltrim(Clie->End_Clie)+", "+Alltrim(Clie->Nmr_Clie)+" "+Alltrim(Clie->Cid_Clie)+" - "+Clie->Est_Clie)

MemoWrit(uRegPath+"\tempgmapdist.html", chtml)

oOle:Navigate2(uRegPath+"\tempgmapdist.html")

hWnd:=oOle:hWnd

ShowWindow(hWnd, 3 ) //SW_MAXIMIZE=3 SW_NORMAL=1 SW_MINIMIZE=6

BringWindowToTop(hWnd)

Return nil

id=code>id=code>

arquivo html => gmapdist.html


var map, geocoder;

var mapDisplay, directionsService;

function initialize() {

var myOptions = {zoom: 15,mapTypeId: google.maps.MapTypeId.ROADMAP};

map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);

geocoder = new google.maps.Geocoder();

var enderDe = "ORIGEM";

var enderAte = "DESTINO";

geocoder.geocode( { 'address': enderAte, 'region' : 'BR'},trataLocs);

initializeDirections ();

calcRota (enderDe, enderAte);

}

function initializeDirections () {

directionsService = new google.maps.DirectionsService();

mapDisplay = new google.maps.DirectionsRenderer();

mapDisplay.setMap(map);

mapDisplay.setPanel(document.getElementById("panel")) }

function calcRota(endDe, endPara) {

var request = {

origin:endDe,

destination:endPara,

travelMode: google.maps.DirectionsTravelMode.DRIVING

};

directionsService.route(request, function(response, status) {

if (status == google.maps.DirectionsStatus.OK) {

mapDisplay.setDirections(response) }

}) }

function trataLocs (results, status) {

var elem = document.getElementById('msg');

if (status == google.maps.GeocoderStatus.OK) {

map.setCenter(results[0].geometry.location);

var marker = new google.maps.Marker({

map: map,

position: results[0].geometry.location });

if (results.length > 1) {

var i, txt = '';

elem.innerHTML = 'O endereço exato não foi localizado - há ' + results.length.toString() + ' resultados aproximados.

';

for (i = 0; i < results.length; i++) {

txt = txt + '

if (i == 0)

txt = txt + ' selected="selected"';

txt = txt + '>' + results.formatted_address + '

';

}

txt = txt + ''

elem.innerHTML = elem.innerHTML + txt;

}

} else

elem.innerHTML = 'Erro no tratamento do endereço :

' + status + '';

}

id=code>

id=code>

mapsdistw.png

Editado por - sistem on 27/11/2012 17:33:01

Link to comment
Share on other sites

voce tinha postado inicialmente uma imagem com várias rotas como que ficaria no exemplo acima ?

"varios" DESTINO ?

cHtml := StrTran( cHtml, "DESTINO", Alltrim(Clie->End_Clie)+", "+Alltrim(Clie->Nmr_Clie)+" "+Alltrim(Clie->Cid_Clie)+" - "+Clie->Est_Clie)

xharbour 1.1.0 + gtwvw + fw 8.04+vsx e começando + xbrowse

migrando p/ o 10.2 e nfe (classe do gilmer) e futuramente paf-ecf

msn..: zazibr@hotmail.com

skype: zazibr

Daniel lopes Filho

Campo Grande/MS

Link to comment
Share on other sites

amigo o exemplo acima é a distância geodesica entre 2 pontos(menor distancia em uma esfera(globo))

no seu caso teria que usar gPolyline do google maps, vamos ver como fica.

Lembrei de topologia de rede :)

o amigo quer ligar um ponto a outro ponto esse ultimo ponto ligar um terceiro ponto ou seria em forma de estrela?

Link to comment
Share on other sites

vlw gente

depois irei postar exemplo com mutiplos pontos com gpolyline para o amigo zazibr

obs: buscando o html de um host da internet com o exemplo acima


Function GOOGLE_MAPA_DIST()

Local cHtml:="", oOle

If !IsInternet()

Msgalert("não conectado a internet.", "Aviso!")

Return nil

Endif

cHtml := WebConnect():New()

cHtml := cHtml:Open( "http://www.sistem.net.br/gmapdist.html" )

Ferase(uRegPath+"\tempgmapdist.html")

oOle:= CreateObject("InternetExplorer.Application")

oOle:Visible := .t.

oOle:ToolBar := .f.

oOle:StatusBar := .t.

oOle:MenuBar := .f.

// cHtml := MemoRead(uRegPath+"\gmapdist.html") // linha desativada

cHtml := StrTran( cHtml, "ORIGEM", Alltrim(Empr->End_Empr)+", "+Alltrim(Empr->Nmr_Empr)+", "+Alltrim(Empr->Cid_Empr)+" - "+Empr->Est_Empr)

cHtml := StrTran( cHtml, "DESTINO", Alltrim(Clie->End_Clie)+", "+Alltrim(Clie->Nmr_Clie)+" "+Alltrim(Clie->Cid_Clie)+" - "+Clie->Est_Clie)

MemoWrit(uRegPath+"\tempgmapdist.html", chtml)

oOle:Navigate2(uRegPath+"\tempgmapdist.html")

hWnd:=oOle:hWnd

ShowWindow(hWnd, 3 ) //SW_MAXIMIZE=3 SW_NORMAL=1 SW_MINIMIZE=6

BringWindowToTop(hWnd)

Return nil

id=code>id=code>

a classe WebConnect tem aqui no forum é soh pesquisar, nao lembro o autor +acho que seja o lailton

Link to comment
Share on other sites


*=======================

#include "fivewin.ch"

Class WebConnect

Data oWeb

Method New() Constructor

Method Open()

Method End() INLINE ::oWeb:=Self:=Nil

EndClass

*--

Method New() Class WebConnect

Try

::oWeb := CreateObject('MSXML2.XMLHTTP')

Catch

::oWeb := CreateObject('Microsoft.XMLHTTP')

End

Return Self

*--

Method Open( cUrl ) Class WebConnect

Local cRet := ""

If ValType( cUrl ) == 'U'

Return cRet

EndIf

Try

::oWeb:Open("POST",cUrl,.f.)

::oWeb:Send()

cRet := ::oWeb:responseBody

Catch; End

Return cRet

id=code>id=code>
Link to comment
Share on other sites

OBRIGADO AMIGO, ESTA FUNCIONANDO

POREM

cHtml:Open( "http://www.sistem.net.br/gmapdist.html" )

TEM COMO MUDAR PARA ALGO DE DOMINIO PULICO, pois se voce mudar o endereço do seu site ele para.

aproveitando de sua boa vontade, ele poderia abrir com o navegador padrão do usaurio.

pois esse I.E. é uma caca...

Editado por - marcioe on 06/12/2012 09:28:21

Link to comment
Share on other sites

macio

TEM COMO MUDAR PARA ALGO DE DOMINIO PULICO?

tem, mais vc pode usar no proprio computador

subistituir as linhas:

cHtml := WebConnect():New()

cHtml := cHtml:Open( "http://www.sistem.net.br/gmapdist.html" )

por:

cHtml := MemoRead(uRegPath+"\gmapdist.html")

o codigo gmapdist.html ta logo acima

eu tenho o google chrome portable e testei assim e funciona, linha de comando:

WINEXEC( ....googlechromeportable e:\test\tempgmapdist.html se preferir usar o codigo de seu computador

nao tenho outro navegado para teste

Editado por - sistem on 06/12/2012 10:25:43

Link to comment
Share on other sites

  • 4 years later...

passei o link no inicio do post, que faz isto:

Function GOOGLE_MAPA_DIST()
Local cHtml:="", oOle

     If !IsInternet()
        Msgalert("não conectado a internet.", "Aviso!")
        Return nil
     Endif

//     cHtml := WebConnect():New()
//     cHtml := cHtml:Open( "http://www.testeeeeeeee.com/gmapdist.html" )  // arquivo na internet 

       cHtml := MemoRead("e:\gmapdist.html")     // arquivo no computador local  unidade E: como exemplo
       
     Ferase("e:\tempgmapdist.html")

     TRY
      oOle:= CreateObject("InternetExplorer.Application")
     CATCH
      TRY
       oOle:= CreateObject("InternetExplorer.Application")
      CATCH oError
       MsgAlert( "Erro! Internet Explorer não abriu. [" + Ole2TxtError()+ "]" + oError:description )
       Return nil
      END
     END

     oOle:Visible    := .t.
     oOle:ToolBar    := .f.
     oOle:StatusBar  := .t.
     oOle:MenuBar    := .f.

     cHtml := StrTran( cHtml, "ORIGEM", Alltrim(Empr->End_Empr)+", "+Alltrim(Empr->Nmr_Empr)+", "+Alltrim(Empr->Cid_Empr)+" - "+Empr->Est_Empr)
     cHtml := StrTran( cHtml, "DESTINO", Alltrim(Clie->End_Clie)+", "+Alltrim(Clie->Nmr_Clie)+" "+Alltrim(Clie->Cid_Clie)+" - "+Clie->Est_Clie)

     MemoWrit("e:\tempgmapdist.html", chtml)

     oOle:Navigate2("e:\tempgmapdist.html")

     hWnd:=oOle:hWnd
     ShowWindow(hWnd, 3 )         //SW_MAXIMIZE=3 SW_NORMAL=1 SW_MINIMIZE=6
     BringWindowToTop(hWnd)
     oOle := nil

Return nil

o conteudo arquivo gmapdist.html é :

<html><head><title>Mapa Distancia</title>
<script type='text/javascript' src='http://maps.google.com/maps/api/js?v=3.1&sensor=false&language=pt-BR'></script>
<script type='text/javascript'>
var map, geocoder;
var mapDisplay, directionsService;

function initialize() {
var myOptions = {zoom: 15,mapTypeId: google.maps.MapTypeId.ROADMAP};
map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);
geocoder = new google.maps.Geocoder();

var enderDe = "ORIGEM";
var enderAte = "DESTINO";

geocoder.geocode( { 'address': enderAte, 'region' : 'BR'},trataLocs);

initializeDirections ();

calcRota (enderDe, enderAte);
}

function initializeDirections () {
 directionsService = new google.maps.DirectionsService();
 mapDisplay = new google.maps.DirectionsRenderer();
 mapDisplay.setMap(map);
 mapDisplay.setPanel(document.getElementById("panel")) }

function calcRota(endDe, endPara) {
    var request = {
        origin:endDe,
        destination:endPara,
        travelMode: google.maps.DirectionsTravelMode.DRIVING
    };
    directionsService.route(request, function(response, status) {
      if (status == google.maps.DirectionsStatus.OK) {
        mapDisplay.setDirections(response) }
    }) }

function trataLocs (results, status) {
var elem = document.getElementById('msg');
if (status == google.maps.GeocoderStatus.OK) {
 map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location  });
if (results.length > 1) {
 var i, txt = '<select style="font-family:Verdana;font-size:8pt;width=550px;" onchange="mostraEnd(this.options[this.selectedIndex].text);">';
 elem.innerHTML = 'O endereço exato não foi localizado - há ' +  results.length.toString() + ' resultados aproximados.<br />';
 for (i = 0; i < results.length; i++) {
 txt = txt + '<option value="' + i.toString() + '"';
 if (i == 0)
   txt = txt + ' selected="selected"';
 txt = txt + '>' + results[i].formatted_address + '</option>';
}
txt = txt + '</select>'
 elem.innerHTML = elem.innerHTML + txt;
 }
} else
 elem.innerHTML = 'Erro no tratamento do endereço :<br /><b>' + status + '</b>';
 }
</script>
  </head>
  <body onload='initialize();' style='font-family:Verdana;font-size:8pt;margin:5px 0 5px 0;'>
   <center>
    <div id='map_canvas' style='width:800px;height:450px'></div>
    <div id='panel' style='width:550px;height:450px'></div>
</center>
</html>

o resultado é:

dist.jpg?1490304244

como o topic ta com varios exemplos nao sei se é isto o pretendido

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