Autor Beitrag
Dhakiyah
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 327
Erhaltene Danke: 5

Windows 7
Delphi XE2
BeitragVerfasst: Mi 30.06.10 16:16 
Hallo!
Ich muss die Geographische Daten einer Adresse herausfinden und in eine DB abspeichern.

Jetzt habe ich folgendes gefunden, was eine XML-Datei im WebBrowser anzeigt:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.FormActivate(Sender: TObject);
begin
  WebBrowser1.Navigate('http://maps.google.com/maps/api/geocode/xml?address=Hauptstrasse+1+51143+Koeln&sensor=true');
end;


Das ganze sieht dann so aus:

ausblenden volle Höhe XML-Daten
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
<GeocodeResponse>
<status>OK</status>

<result>
<type>street_address</type>
<formatted_address>Hauptstraße 1, 51143 Köln, Deutschland</formatted_address>

<address_component>
<long_name>1</long_name>
<short_name>1</short_name>
<type>street_number</type>
</address_component>

<address_component>
<long_name>Hauptstraße</long_name>
<short_name>Hauptstraße</short_name>
<type>route</type>
</address_component>

<address_component>
<long_name>Köln</long_name>
<short_name>Köln</short_name>
<type>sublocality</type>
<type>political</type>
</address_component>

<address_component>
<long_name>Zündorf</long_name>
<short_name>Zündorf</short_name>
<type>sublocality</type>
<type>political</type>
</address_component>

<address_component>
<long_name>Köln</long_name>
<short_name>Köln</short_name>
<type>locality</type>
<type>political</type>
</address_component>

<address_component>
<long_name>Köln</long_name>
<short_name>K</short_name>
<type>administrative_area_level_2</type>
<type>political</type>
</address_component>

<address_component>
<long_name>Nordrhein-Westfalen</long_name>
<short_name>NRW</short_name>
<type>administrative_area_level_1</type>
<type>political</type>
</address_component>

<address_component>
<long_name>Deutschland</long_name>
<short_name>DE</short_name>
<type>country</type>
<type>political</type>
</address_component>

<address_component>
<long_name>51143</long_name>
<short_name>51143</short_name>
<type>postal_code</type>
</address_component>

<geometry>

<location>
<lat>50.8609300</lat>
<lng>7.0338200</lng>
</location>
<location_type>ROOFTOP</location_type>

<viewport>

<southwest>
<lat>50.8577824</lat>
<lng>7.0306724</lng>
</southwest>

<northeast>
<lat>50.8640776</lat>
<lng>7.0369676</lng>
</northeast>
</viewport>
</geometry>
</result>
</GeocodeResponse>


Ich will lediglich an diese
ausblenden XML-Daten
1:
2:
3:
4:
5:
6:
<geometry>

<location>
<lat>50.8609300</lat>
<lng>7.0338200</lng>
</location>


Daten... Wie komme ich an diese Daten? Das ich die entweder in eine Textdatei schreiben kann oder gleich einer Variablen zuweise...

Kann mir jemand helfen? DANKE !!!

Gruß Jasmin

_________________
Es ist soooo flauschig !!!
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Mi 30.06.10 16:22 
Einerseits könntest du die Daten in eine XML-Komponente laden (die von den Jedis zum Beispiel).

Oder du spielst dich ein bisschen mit PosEx und Copy herum.

lg elundril

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
Dhakiyah Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 327
Erhaltene Danke: 5

Windows 7
Delphi XE2
BeitragVerfasst: Mi 30.06.10 16:31 
Aber wie?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
var TestXML : IXMLDocument
...
  WebBrowser1.Navigate('http://maps.google.com/maps/api/geocode/xml?address=Hauptstrasse+1+51143+Koeln&sensor=true');
  myfirstXML...??? := WebBrowser1....???;

_________________
Es ist soooo flauschig !!!
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Mi 30.06.10 16:34 
statt eine Webbrowsers würde ich per HTTP-Komponente oder ExtActns.TDownloadUrl
zugreifen, in eine Stringlist laden und die interessanten Zeilen auswerten.
Dhakiyah Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 327
Erhaltene Danke: 5

Windows 7
Delphi XE2
BeitragVerfasst: Mi 30.06.10 16:40 
Beispiel?

_________________
Es ist soooo flauschig !!!
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Mi 30.06.10 16:53 
Ganz Quick and Dirty ohne TempDir uund Fehlerprüfung

Du müsstes es alf Funktion: boolean kapseln
mit (URL:String;var lat,lng:Double)
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
uses ExtActns;

procedure TForm5.Button2Click(Sender: TObject);
var

 i:Integer;
 sl:TStringList;
 IsIntrest:Boolean;
 lat,lng:Double;
begin
 sl:=TStringList.create;
 try
 with TDownLoadURL.Create(nildo
    begin
    Filename  := 'C:\temp\test.xml';
    URL := 'http://maps.google.com/maps/api/geocode/xml?address=Hauptstrasse+1+51143+Koeln&sensor=true';
       try
      ExecuteTarget(nil);
    except
    end;
    free;
    sl.LoadFromFile('C:\temp\test.xml');
    end;

  IsIntrest := false;
  for I := 0 to sl.Count - 1 do
    begin
      if pos('</location>',sl[i])>0 then IsIntrest := false;
      if IsIntrest then
        begin
           if pos('<lat>',sl[i])>0 then lat := StrToFloat(Stringreplace(Stringreplace(Stringreplace(Trim(sl[i]),'<lat>','',[]),'</lat>','',[]),'.',',',[]))
           else if pos('<lng>',sl[i])>0 then lng := StrToFloat(Stringreplace(Stringreplace(Stringreplace(Trim(sl[i]),'<lng>','',[]),'</lng>','',[]),'.',',',[]));
        end;
      if pos('<location>',sl[i])>0 then IsIntrest := true;
    end;

 finally
  sl.Free;
 end;
 ShowMessage(FloatToStr(lat)+'-'+FloatToStr(lng))
end;


---Moderiert von user profile iconNarses: Beiträge zusammengefasst---

nicht ganz fertig aber ...
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
Function GetTempDir:String;
var
p:Pchar;
begin
p:=stralloc(255);
GetTempPath(255,p);
Result:=p;
strdispose(p);
end;


Function CleanUrl(const s:String):String;
begin
  Result :=StringReplace(
           StringReplace(
           StringReplace(
           StringReplace(s,'ß','ss',[rfReplaceAll])
           ,'ä','ae',[rfReplaceAll])
           ,'ü','ue',[rfReplaceAll])
           ,'ö','oe',[rfReplaceAll])
end;


Function GetLatLng(AURL:String;var lat,lng:Double):Boolean;
var

 i:Integer;
 sl:TStringList;
 IsIntrest:Boolean;
 LFilename:String;
begin
 sl:=TStringList.create;
 Result := false;
 try
 LFileName := IncludeTrailingBackSlash(GetTempDir)+'~tmp.xml';
 with TDownLoadURL.Create(nildo
    begin
    Filename  := LFileName;
    URL := CleanUrl(AUrl);
       try
      ExecuteTarget(nil);
    except
    end;
    free;
    sl.LoadFromFile(LFileName);
    end;

  IsIntrest := false;
  for I := 0 to sl.Count - 1 do
    begin
      if pos('</location>',sl[i])>0 then IsIntrest := false;
      if IsIntrest then
        begin
           try
           if pos('<lat>',sl[i])>0 then lat := StrToFloat(Stringreplace(Stringreplace(Stringreplace(Trim(sl[i]),'<lat>','',[]),'</lat>','',[]),'.',',',[]))
           else if pos('<lng>',sl[i])>0 then lng := StrToFloat(Stringreplace(Stringreplace(Stringreplace(Trim(sl[i]),'<lng>','',[]),'</lng>','',[]),'.',',',[]));
           Result := (lat<>0or (lng<>0);
           except
           end;
        end;
      if pos('<location>',sl[i])>0 then IsIntrest := true;
    end;

 finally
  sl.Free;
 end;

end;