Registriert seit: 4. Nov 2005
Ort: Basel
442 Beiträge
Delphi XE2 Enterprise
|
AW: Google Maps über COM (Component Object Model)
18. Apr 2012, 14:19
Schön, daß es funktioniert!
Aber was meinst Du mit "nach MarkerOptions"?
2 Post vorher im Quelltext:
Delphi-Quellcode:
// Marker.OwnsData:=false;
// Marker.Data:=InfoWindow;
Wenn dies Codezeilen aktiviert werden und weiter unten ( 14 Zeilen ) dies deaktiviert werden, erhalte ich die EAccessViolation.
Der Code sieht nun so aus:
Delphi-Quellcode:
procedure Tfrm_map.btn_Encode_batchClick(Sender: TObject);
var
LatLng: TLatLng;
Lat, Lng, InfoWindow_String: String;
InfoWindow: TInfoWindow;
Marker: TMarker;
MarkerData: array of TMarkerData;
MarkerOptions: TMarkerOptions;
MyImage, MyShadow: TMarkerImage;
sql_count: Integer;
begin
with Script do
begin
Marker:=nil; //falls keine Daten in der Tabelle vorliegen
DM_map.Map.First;
while not DM_map.Map.Eof do
begin
if DM_map.Map.FieldByName('POS_LAT').Text = '' then
DM_map.Map.Next
else
Lat:=DM_map.Map.FieldByName('POS_LAT').Text;
Lng:=DM_map.Map.FieldByName('POS_LNG').Text;
LatLng:=New(Google.Maps.LatLng(StrToFloatDef(Lat,0,'.'),
StrToFloatDef(Lng,0,'.')));
//
InfoWindow_String:=(
DM_map.Map.FieldByName('AREA').AsString + '<br>'+
DM_map.Map.FieldByName('NAME').AsString + '<br>'+
DM_map.Map.FieldByName('STR').AsString + '<br>'+
DM_map.Map.FieldByName('PLZ').AsString + '-'+
DM_map.Map.FieldByName('CITY').AsString + '<br>'+'TEL:' +
DM_map.Map.FieldByName('TEL').AsString + '<br>'+'______________________ <br>'+'Camp ' + '- '+
DM_map.Map.FieldByName('C_NO').AsString);
//
InfoWindow:=New(Google.Maps.InfoWindow);
InfoWindow.Content:=InfoWindow_String;
if DM_map.Map.FieldByName('ACCEPTANCE').AsString= '1' then
begin
// Imagesettings for this Marker
MyImage:=New(Google.Maps.MarkerImage(MarkerURL+table_name+'.png',
//This marker is 28 pixels wide by 35 pixels tall.
New(Google.Maps.Size(28,35)),
//The origin for this image is 0,0.
New(Google.Maps.Point(0,0)),
//The anchor for this image is the base of the flagpole at 6,20.
New(Google.Maps.Point(6,20))));
end;
if DM_map.Map.FieldByName('ACCEPTANCE').AsString= '2' then
begin
// Imagesettings for this Marker
MyImage:=New(Google.Maps.MarkerImage(MarkerURL+table_name+'_Conditional'+'.png',
New(Google.Maps.Size(28,35)),
New(Google.Maps.Point(0,0)),
New(Google.Maps.Point(6,20))));
end;
if DM_map.Map.FieldByName('ACCEPTANCE').AsString= '3' then
begin
// Imagesettings for this Marker
MyImage:=New(Google.Maps.MarkerImage(MarkerURL+table_name+'_no'+'.png',
New(Google.Maps.Size(28,35)),
New(Google.Maps.Point(0,0)),
New(Google.Maps.Point(6,20))));
end;
if DM_map.Map.FieldByName('ACCEPTANCE').AsString= '4' then
begin
// Imagesettings for this Marker
MyImage:=New(Google.Maps.MarkerImage(MarkerURL+table_name+'_maybe'+'.png',
New(Google.Maps.Size(28,35)),
New(Google.Maps.Point(0,0)),
New(Google.Maps.Point(6,20))));
end;
if DM_map.Map.FieldByName('ACCEPTANCE').AsString= '' then
begin
MyImage:=New(Google.Maps.MarkerImage(MarkerURL+table_name+'.png',
New(Google.Maps.Size(28,35)),
New(Google.Maps.Point(0,0)),
New(Google.Maps.Point(6,20))));
end;
MarkerOptions:=TMarkerOptions.Create;
with MarkerOptions do
begin
Map:=Maps[0];
Position:=LatLng;
MarkerOptions.Title:= DM_map.Map.FieldByName('NAME').AsString;
IconImage:=MyImage;
end;
Marker:=New(Google.Maps.Marker(MarkerOptions));
Marker.OnClick:=MarkerClick;
MarkerOptions.Free; //momentan noch etwas auf den Speicher achten
//-> in der neuen Version stelle ich auf Interfaces um,
//so daß die Freigabe automatisch erfolgt
LatLng.Free; //gleicher Grund
Marker.OwnsData:=false;
Marker.Data:=InfoWindow;
DM_map.Map.Next;
end;
if assigned(Marker)
then Maps[0].SetCenter(Marker.GetPosition); //nur den letzten Marker zentrieren
end;
end;
|