Amiguinhos
Eu desenvolvi um método baseado no cd Guia de Ruas, em conjunto com a biblioteca ADOxB eu manipulava os arquivos .XML, obtinha o numero de pagina e apresentava a imagem da pagina que continha o endereço pesquisado.
Mas como eu estava mexendo com Activex, pensei em inserir o mesmo em um diálogo e acrescentar alguns recursos usando a API do Google e um codigo encontrado em um forum internacional de programadores.
O problema que o mesmo pedia que fosse passado codigos de coordenadas geodésicas e apesar de meu arquivo de CEPs conter estes numeros, nem todos os registros tinham a coordenada.
Felizmente, recentemente, um outro forense apresentou um novo código e passei a trabalhar no mesmo mantendo minha estrutura de verificação conseguindo o que posto a seguir:
Resultado:
Codigo da janela .RC:
Código: Selecionar todos
GoogleMap DIALOG 17, 35, 418, 316
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Localizacao de Endereco"
FONT 8, "MS Sans Serif"
{
EDITTEXT 101, 59, 246, 155, 28, ES_MULTILINE | WS_BORDER | WS_TABSTOP
EDITTEXT 102, 59, 277, 75, 12
EDITTEXT 103, 138, 277, 76, 12
PUSHBUTTON "Mostras mapa deste endereço", 5, 59, 293, 156, 14
PUSHBUTTON "Fechar", 2, 364, 298, 50, 14
CONTROL "", 100, "TActiveX", 0 | WS_CHILD | WS_VISIBLE, 4, 4, 409, 230
LTEXT "Endereco:", -1, 8, 248, 46, 8
LTEXT "Bairro/Cidade:", -1, 8, 279, 49, 8
GROUPBOX "Pesquisar pelo endereço", -1, 4, 237, 215, 76, BS_GROUPBOX
EDITTEXT 105, 277, 246, 60, 12
LTEXT "C.E.P.:", -1, 226, 249, 48, 8
GROUPBOX "Pesquisar pelo CEP", -1, 222, 237, 192, 43, BS_GROUPBOX
PUSHBUTTON "Mostrar mapa deste CEP", 6, 277, 261, 134, 14
PUSHBUTTON "Confirmar CEP...", 7, 340, 245, 71, 14
EDITTEXT 104, 228, 263, 16, 12, NOT WS_VISIBLE | WS_BORDER | WS_TABSTOP
CONTROL "TBitMap", 115, "TBitMap", WS_CHILD | WS_VISIBLE, 223, 282, 116, 34
}
Codigo do .PRG:
Código: Selecionar todos
...
DEFINE BUTTON ... GoogleMap(CLIENTES->ENDERECO, ;
CLIENTES->BAIRRO, ;
CLIENTES->CIDADE,;
CLIENTES->ESTADO,;
CLIENTES->CEP )
...
Function GoogleMap( cEndereco, cBairro, cCidade, cEstado, cCep )
LOCAL oGMapDlg, oActiveX
DEFAULT cEndereco := "MARIO MAURO RAMOS MATTOSO",;
cBairro := "PIRITUBA", cCidade := "SAO PAULO",;
cEstado := "SP", cCep := "05171-340"
M->ENDERECO := cEndereco := alltrim(OemToAnsi(cEndereco)) + space(30)
M->BAIRRO := cBairro := alltrim(OemToAnsi(cBairro)) + space(30)
M->CIDADE := cCidade := alltrim(OemToAnsi(cCidade)) + space(30)
M->ESTADO := cEstado
M->CEP := cCep
DEFINE DIALOG oGMapDlg RESOURCE "GoogleMap"
REDEFINE ACTIVEX oActiveX ID 100 OF oGMapDlg PROGID "Shell.Explorer"
REDEFINE GET oGet101 VAR cEndereco MEMO ID 101 OF oGMapDlg FONT oFont0
oGet101:bChange:={ |nKey,nFlags,Self| iif(nKey==13,Salto(Self,oGet101,oGMapDlg,len(M->ENDERECO)),)}
REDEFINE GET oGet102 VAR cBairro PICTURE "@!" ID 102 OF oGMapDlg FONT oFont0
REDEFINE GET oGet103 VAR cCidade PICTURE "@!" ID 103 OF oGMapDlg FONT oFont0
REDEFINE GET oGet104 VAR cEstado PICTURE "@!" ID 104 OF oGMapDlg FONT oFont0
REDEFINE GET oGet105 VAR cCep PICTURE "99999-999" ID 105 OF oGMapDlg FONT oFont0
//REDEFINE BITMAP oBitMap ID 115 OF oGMapDlg FILENAME "recursos\googlem.bmp"
REDEFINE BUTTON ID 5 OF oGMapDlg ACTION Show( cEndereco, cBairro, cCidade, cEstado, cCep, oActiveX )
REDEFINE BUTTON ID 6 OF oGMapDlg ACTION Show( , , , , cCep, oActiveX )
REDEFINE BUTTON ID 7 OF oGMapDlg ACTION .T.
ACTIVATE DIALOG oGMapDlg CENTERED ON INIT Show( cEndereco, cBairro, cCidade, cEstado, cCep, oActiveX )
return nil
function Show( cEndereco, cBairro, cCidade, cEstado, cCep, oActiveX )
local cHtml := MemoRead( "gmap.html",255 )
if cEndereco=NIL .and. cBairro=NIL
cEndereco := "BRASIL"
cCidade := ""
cEstado := ""
endif
cBairro := ""
cHtml := StrTran( cHtml, "<<ENDERECO>>", AllTrim( cEndereco ) )
cHtml := StrTran( cHtml, "<<BAIRRO>>" , AllTrim( cBairro ) )
cHtml := StrTran( cHtml, "<<CIDADE>>" , AllTrim( cCidade ) )
cHtml := StrTran( cHtml, "<<ESTADO>>" , AllTrim( cEstado ) )
cHtml := StrTran( cHtml, "<<CEP>>" , AllTrim( cCep ) )
MemoWrit( "temp.html", cHtml )
oActiveX:Do( "Navigate2", CurDrive() + ":\" + CurDir() + "\temp.html" )
return nil
Codigo GMAP.HTML:
Código: Selecionar todos
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title> </title>
<script src="http://maps.google.com/maps?file=api&v=2.x&key=ABQIAAAAtOjLpIVcO8im8KJFR8pcMhQjskl1-YgiA_BGX2yRrf7htVrbmBTWZt39_v1rJ4xxwZZCEomegYBo1w" type="text/javascript"></script>
<script type="text/javascript">
var map = null;
var geocoder = null;
var coords = null;
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
geocoder = new GClientGeocoder();
}
}
function showAddress(address, cAddressName) {
if (geocoder) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
showAddress2('<<CIDADE>>');
} else {
map.setCenter(point, 15);
var marker = new GMarker(point);
map.addOverlay(marker);
coords = marker.getPoint();
var curl = cAddressName + "<p>" + coords.toUrlValue(6) + "</p>"
var button = '<input type="button" value="Imprimir" onClick="window.print()"/>;'
curl = curl + button
}
}
);
}
}
function showAddress2(address) {
if (geocoder) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert(address + " nao encontrado");
} else {
map.setCenter(point, 15);
var marker = new GMarker(point);
map.addOverlay(marker);
marker.openInfoWindowHtml(address);
}
}
);
}
}
</script>
</head>
<body onload="initialize(); showAddress('<<ENDERECO>>, <<CIDADE>> <<BAIRRO>> <<CEP>>', '<<ENDERECO>>, <<CIDADE>> <<BAIRRO>> <<CEP>>');" onunload="GUnload()"
<div id="map_canvas" style="width: 573px; height: 340px"></div>
</body>
</html>
Caso tenham problemas ao colar o codigo .HTML acima, peguem no neste link:
http://www.5volution.com/forum/gmap.html
Para se fazer um uso correto destas APIs é necessário criar o seu código em
http://code.google.com/apis/maps e inseri-lo na variável KEY dentro do GMAP.HTML
Boa sorte.