Einzelnen Beitrag anzeigen

azrin.aris

Registriert seit: 25. Dez 2011
3 Beiträge
 
#166

AW: Google Maps über COM (Component Object Model)

  Alt 28. Dez 2011, 23:17
Hi all,

Here is another stumbling block that I encounter

the delphi code is:
Delphi-Quellcode:
procedure TForm1.InitMap(Sender: TObject);
var
  Marker: TMarker;
  MarkerOptions: TMarkerOptions;
  MyMap: TMap;
  MyOptions: TMapOptions;
begin
  with TScript(Sender) do
  begin
    MyOptions:=TMapOptions.Create;
    with MyOptions do
    begin
      Zoom:=4;
      Center:=New(Google.Maps.LatLng(-25.363882,131.044922));
      MapTypeID:=Google.Maps.MapTypeID.Roadmap;
    end;
    MyMap:=New(Google.Maps.Map(MyOptions));
    MarkerOptions:=TMarkerOptions.Create;
    with MarkerOptions do
    begin
      Position:=MyMap.GetCenter;
      Map:=MyMap;
      Title:='Click to zoom';
    end;
    Marker:=New(Google.Maps.Marker(MarkerOptions));
    {$IFDEF USE_ANONYMOUS_METHODS}
    Marker.OnClick:=
      procedure(Sender: TObject; Event: TEvent)
      begin
        if MyMap.GetZoom=8
          then MyMap.SetZoom(4)
          else MyMap.SetZoom(8);
        MyMap.SetCenter(Marker.GetPosition);
      end;
    {$ELSE}
    Marker.OnClick:=MarkerClick;
    {$ENDIF}
  end;
end;

{$IFNDEF USE_ANONYMOUS_METHODS}
procedure TForm1.MarkerClick(Sender: TObject; Event: TEvent);
begin
  with Script do
  begin
    if Maps[0].GetZoom=8
      then Maps[0].SetZoom(4)
      else Maps[0].SetZoom(8);
    Maps[0].SetCenter(TMarker(Sender).GetPosition);
  end;
end;
{$ENDIF}
and the C++ code is:
Code:
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <SHDocVw.hpp>
#include <Vcl.OleCtrls.hpp>
#include "gmAPI.hpp"
#include "gmMap.hpp"
#include "gmOverlaysMarker.hpp"
#include "gmEvents.hpp"
#include "HTMLObjects.hpp"
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:   // IDE-managed Components
    TWebBrowser *WebBrowser1;
    void __fastcall FormCreate(TObject *Sender);
private:   // User declarations
    TScript *Script;
    void __fastcall InitMap(TObject *Sender);

public:       // User declarations
    __fastcall TForm1(TComponent* Owner);

    void __fastcall MarkerClick(TObject* Sender, Gmevents::TEvent Event);

};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif



//Unit1.cpp

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

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"

#pragma link "gmMap"
#pragma link "winInet.lib"

TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
   : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
   Script = new TScript(WebBrowser1);
   Script->LoadAPIAsync(InitMap);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::InitMap(TObject *Sender)
{

   int n;
   TMarker *Marker;
   TMarkerOptions *MarkerOptions;
   TLatLng *MyLatLng;
   TMap *MyMap;

   TScript *Script = dynamic_cast<TScript*>(Sender);

   TMapOptions *MyOptions = new TMapOptions;

   MyOptions->Zoom = 4;
   MyOptions->Center = Script->Google->Maps->LatLng(-25.363882,131.044922);
   MyOptions->MapTypeID = Script->Google->Maps->MapTypeID->Roadmap;

   MyMap = Script->Google->Maps->Map(MyOptions);

   MarkerOptions = new TMarkerOptions;

   MarkerOptions->Position = MyMap->GetCenter();
   MarkerOptions->Map      = MyMap;
   MarkerOptions->Title   = "Click to Zoom";
   Marker = Script->Google->Maps->Marker(MarkerOptions);
   Marker->OnClick = MarkerClick;  //[BCC32 Error] Member function must be called or its address taken

   delete MyOptions;
   delete MarkerOptions;

}
//---------------------------------------------------------------------------
void __fastcall TForm1::MarkerClick(TObject* Sender, Gmevents::TEvent Event)
{
   if(Script->Google->Maps[0]->GetZoom==8) // Error :E2288 Pointer to structure required on left side of -> or ->*
   {

   }
}
//---------------------------------------------------------------------------

I could not get the MarkerClick to be assigned to Marker->OnClick.

Also I could not find the Script->Google->Maps[0]->GetZoom() function.

Attached is the hpp file converted by C++ Builder


Anyhelp would be very much appreciated.

Thank you
Angehängte Dateien
Dateityp: zip gmAPI.zip (6,1 KB, 57x aufgerufen)

Geändert von azrin.aris (28. Dez 2011 um 23:34 Uhr)
  Mit Zitat antworten Zitat