AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Google ReverseGeocoding

Ein Thema von MapMan · begonnen am 9. Mär 2011 · letzter Beitrag vom 9. Mär 2011
 
MapMan

Registriert seit: 7. Apr 2008
11 Beiträge
 
Delphi 7 Architect
 
#1

Google ReverseGeocoding

  Alt 9. Mär 2011, 00:33
Beim Reverse Geocoding wird aus geografischen Koordinaten (Längengrad, Breitengrad) eine Adresse ermittelt.

Das geht recht einfach mit dem Google ReverseGeocoding-API http://code.google.com/intl/de-DE/ap...verseGeocoding

Eine kleine Klasse kapselt die Kernmethode ReverseGeocode. Zur Kommunikation mit dem API wird ein Indy HTTP-Client verwendet.

Delphi-Quellcode:
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;
Google liefert eine Menge Daten zurück, interessant ist aber primär die formatierte Adresse.
Wer möchte, kann sich aus dem Abfrageergebis sein individuelles Format erzeugen.

Code:
,
{
  "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
        }
      }
    }
  } ]
}
Im Anhang die Demo-App
Angehängte Dateien
Dateityp: zip GoogleReverseGeocoding.zip (254,3 KB, 79x aufgerufen)

Geändert von MapMan ( 9. Mär 2011 um 14:31 Uhr)
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 23:34 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