![]() |
Google ReverseGeocoding
Liste der Anhänge anzeigen (Anzahl: 1)
Beim Reverse Geocoding wird aus geografischen Koordinaten (Längengrad, Breitengrad) eine Adresse ermittelt.
Das geht recht einfach mit dem Google ReverseGeocoding-API ![]() Eine kleine Klasse kapselt die Kernmethode ReverseGeocode. Zur Kommunikation mit dem API wird ein Indy HTTP-Client verwendet.
Delphi-Quellcode:
Google liefert eine Menge Daten zurück, interessant ist aber primär die formatierte Adresse.
const
Hdr='"formatted_address": "'; URL='http://maps.google.com/maps/api/geocode/json?latlng=%3.8f,%3.8f&sensor=true'; function TGoogleReverseGeocode.ReverseGeocode(Latitude, Longitude: double):string; begin s:=UTF8Decode(IdHTTP.Get(format(URL,[Latitude, Longitude],FormatSettings))); Idx:=pos(Hdr,s); if Idx<>0 then begin Idx:=Idx+22; while s[Idx]<>'"' do begin Result:=Result+s[Idx]; inc(Idx); end; end else Result:='?'; end; Wer möchte, kann sich aus dem Abfrageergebis sein individuelles Format erzeugen.
Code:
Im Anhang die Demo-App
,
{ "status": "OK", "results": [ { "types": [ "street_address" ], "formatted_address": "Schloßstraße 27, 56068 Koblenz, Germany", "address_components": [ { "long_name": "27", "short_name": "27", "types": [ "street_number" ] }, { "long_name": "Schloßstraße", "short_name": "Schloßstraße", "types": [ "route" ] }, { "long_name": "Koblenz", "short_name": "Koblenz", "types": [ "sublocality", "political" ] }, { "long_name": "Koblenz", "short_name": "Koblenz", "types": [ "locality", "political" ] }, { "long_name": "Koblenz", "short_name": "KO", "types": [ "administrative_area_level_2", "political" ] }, { "long_name": "Rheinland-Pfalz", "short_name": "RP", "types": [ "administrative_area_level_1", "political" ] }, { "long_name": "Germany", "short_name": "DE", "types": [ "country", "political" ] }, { "long_name": "56068", "short_name": "56068", "types": [ "postal_code" ] } ], "geometry": { "location": { "lat": 50.3564800, "lng": 7.5956700 }, "location_type": "ROOFTOP", "viewport": { "southwest": { "lat": 50.3533324, "lng": 7.5925224 }, "northeast": { "lat": 50.3596276, "lng": 7.5988176 } } } }, { "types": [ "postal_code" ], "formatted_address": "56068 Koblenz, Germany", "address_components": [ { "long_name": "56068", "short_name": "56068", "types": [ "postal_code" ] }, { "long_name": "Koblenz", "short_name": "Koblenz", "types": [ "locality", "political" ] }, { "long_name": "Koblenz", "short_name": "KO", "types": [ "administrative_area_level_2", "political" ] }, { "long_name": "Rheinland-Pfalz", "short_name": "RP", "types": [ "administrative_area_level_1", "political" ] }, { "long_name": "Germany", "short_name": "DE", "types": [ "country", "political" ] } ], "geometry": { "location": { "lat": 50.3511528, "lng": 7.5951959 }, "location_type": "APPROXIMATE", "viewport": { "southwest": { "lat": 50.3285887, "lng": 7.5818021 }, "northeast": { "lat": 50.3659432, "lng": 7.6090369 } }, "bounds": { "southwest": { "lat": 50.3285887, "lng": 7.5818021 }, "northeast": { "lat": 50.3659432, "lng": 7.6090369 } } } }, { "types": [ "administrative_area_level_2", "political" ], "formatted_address": "Koblenz, Germany", "address_components": [ { "long_name": "Koblenz", "short_name": "KO", "types": [ "administrative_area_level_2", "political" ] }, { "long_name": "Rheinland-Pfalz", "short_name": "RP", "types": [ "administrative_area_level_1", "political" ] }, { "long_name": "Germany", "short_name": "DE", "types": [ "country", "political" ] } ], "geometry": { "location": { "lat": 50.3386144, "lng": 7.5885240 }, "location_type": "APPROXIMATE", "viewport": { "southwest": { "lat": 50.2829080, "lng": 7.4826460 }, "northeast": { "lat": 50.4096970, "lng": 7.6963740 } }, "bounds": { "southwest": { "lat": 50.2829080, "lng": 7.4826460 }, "northeast": { "lat": 50.4096970, "lng": 7.6963740 } } } }, { "types": [ "locality", "political" ], "formatted_address": "Koblenz, Germany", "address_components": [ { "long_name": "Koblenz", "short_name": "Koblenz", "types": [ "locality", "political" ] }, { "long_name": "Koblenz", "short_name": "KO", "types": [ "administrative_area_level_2", "political" ] }, { "long_name": "Rheinland-Pfalz", "short_name": "RP", "types": [ "administrative_area_level_1", "political" ] }, { "long_name": "Germany", "short_name": "DE", "types": [ "country", "political" ] } ], "geometry": { "location": { "lat": 50.3566962, "lng": 7.5996166 }, "location_type": "APPROXIMATE", "viewport": { "southwest": { "lat": 50.2829080, "lng": 7.4826460 }, "northeast": { "lat": 50.4096970, "lng": 7.6963740 } }, "bounds": { "southwest": { "lat": 50.2829080, "lng": 7.4826460 }, "northeast": { "lat": 50.4096970, "lng": 7.6963740 } } } }, { "types": [ "administrative_area_level_1", "political" ], "formatted_address": "Rhineland-Palatinate, Germany", "address_components": [ { "long_name": "Rheinland-Pfalz", "short_name": "RP", "types": [ "administrative_area_level_1", "political" ] }, { "long_name": "Germany", "short_name": "DE", "types": [ "country", "political" ] } ], "geometry": { "location": { "lat": 50.1183460, "lng": 7.3089527 }, "location_type": "APPROXIMATE", "viewport": { "southwest": { "lat": 48.9666617, "lng": 6.1123660 }, "northeast": { "lat": 50.9423250, "lng": 8.5081190 } }, "bounds": { "southwest": { "lat": 48.9666617, "lng": 6.1123660 }, "northeast": { "lat": 50.9423250, "lng": 8.5081190 } } } }, { "types": [ "country", "political" ], "formatted_address": "Germany", "address_components": [ { "long_name": "Germany", "short_name": "DE", "types": [ "country", "political" ] } ], "geometry": { "location": { "lat": 51.1656910, "lng": 10.4515260 }, "location_type": "APPROXIMATE", "viewport": { "southwest": { "lat": 47.2701270, "lng": 5.8662579 }, "northeast": { "lat": 55.0815000, "lng": 15.0418321 } }, "bounds": { "southwest": { "lat": 47.2701270, "lng": 5.8662579 }, "northeast": { "lat": 55.0815000, "lng": 15.0418321 } } } } ] } |
AW: Google ReverseGeocoding
Hallo MapMan,
guter Beitrag! :thumb: Vier kleine Anmerkungen:
|
AW: Google ReverseGeocoding
Hallo Thom,
Zitat:
Zitat:
Sollte durch
Delphi-Quellcode:
jetzt überall laufen.
FormatSettings.DecimalSeparator:='.';
Zitat:
Das gute, alte Arbeitspferd an das ich auch gekettet bin. Ich habe einfach nicht die Zeit meine Produktivprojekte zu migrieren. Aber da schein ich nicht allein zu sein. Zitat:
Macht Sinn, wenn man mehr braucht als die formatierte Adresse. Aber dafür ist das mit Kanonen auf Spatzen geschossen. Und XML bläst die Google-Response nochmal um Faktor 2 auf. Übrigens zieht Google wohl die Notbremse bei mehr als 2500 ReverseGeocodings pro Tag. Schreiben die, muss ich aber mal testen... |
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:52 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz