Hola, estoy tratando de implementar el soporte de los mapas de Google en mi aplicación. Utilizando la API de Google genero mi HTML desde código para utilizar las funciones basicas de mostrar el mapa y centrarlo utilizando una latitud y una longitud y añadir una imagen de marca de ubicación.
Hasta ahí genial!, el problema viene cuando necesito recoger la latitud y la longitud del mapa al "clickear" en él. En Delphi hay muchos ejemplos que funcionan, pero en C++ se me hace muy complicado traducir dicho código...
Encuentro estos dos ejemplos en Delphi donde muestra la manera de hacerlo:
https://theroadtodelphi.com/2011/06/...a-mouse-click/
http://delphidabbler.com/tips/56
Aquí esta la función de la "chicha" que me tiene loco...
Código:
procedure TFrmMain.WebBrowser1CommandStateChange(ASender: TObject; Command: Integer; Enable: WordBool);
var
ADocument : IHTMLDocument2;
ABody : IHTMLElement2;
Lat : string;
Lng : string;
function GetIdValue(const Id : string):string;
var
Tag : IHTMLElement;
TagsList : IHTMLElementCollection;
Index : Integer;
begin
Result:='';
TagsList := ABody.getElementsByTagName('input');
for Index := 0 to TagsList.length-1 do
begin
Tag:=TagsList.item(Index, EmptyParam) As IHTMLElement;
if CompareText(Tag.id,Id)=0 then
Result := Tag.getAttribute('value', 0);
end;
end;
begin
if TOleEnum(Command) <> CSC_UPDATECOMMANDS then
Exit;
ADocument := WebBrowser1.Document as IHTMLDocument2;
if not Assigned(ADocument) then
Exit;
if not Supports(ADocument.body, IHTMLElement2, ABody) then
exit;
Lat :=GetIdValue('LatValue');
Lng :=GetIdValue('LngValue');
if (Lat<>'') and (Lng<>'') and ((Lat<>Latitude.Text) or (Lng<>Longitude.Text)) then
begin
Latitude.Text :=Lat;
Longitude.Text:=Lng;
AddLatLngToList(Lat, Lng);
end;
end;
O bien:
Código:
function GetElementById(const Doc: IDispatch; const Id: string): IDispatch;
var
Document: IHTMLDocument2; // IHTMLDocument2 interface of Doc
Body: IHTMLElement2; // document body element
Tags: IHTMLElementCollection; // all tags in document body
Tag: IHTMLElement; // a tag in document body
I: Integer; // loops thru tags in document body
begin
Result := nil;
// Check for valid document: require IHTMLDocument2 interface to it
if not Supports(Doc, IHTMLDocument2, Document) then
raise Exception.Create('Invalid HTML document');
// Check for valid body element: require IHTMLElement2 interface to it
if not Supports(Document.body, IHTMLElement2, Body) then
raise Exception.Create('Can''t find <body> element');
// Get all tags in body element ('*' => any tag name)
Tags := Body.getElementsByTagName('*');
// Scan through all tags in body
for I := 0 to Pred(Tags.length) do
begin
// Get reference to a tag
Tag := Tags.item(I, EmptyParam) as IHTMLElement;
// Check tag's id and return it if id matches
if AnsiSameText(Tag.id, Id) then
begin
Result := Tag;
Break;
end;
end;
end;
Se trata de recoger el contenido en un TWebBrowser (en este caso un mapa de google maps cargado desde un .html que creo desde mi programa) para mostrar lo almacenado en
Código:
<input type="hidden" id="LatValue" >
<input type="hidden" id="LngValue" >
Llevo varios días buscando pero no consigo encontrar nada que me aclare como hacerlo. He encontrado un proyecto chulo, las GMLib pero como solo necesito poder recoger la latitud y longitud en un click no quisiera añadirlas a mi proyecto.
Alquien podría indicarme como sería esa función en C? O bien donde encontrar más documentación? He terminado leyendo post en alemán y en ruso pero no consigo aclararme !
Muchas gracias por vuestro tiempo, y un saludo!
Jorge.