{ Map Viewer Geolocation Engine for geonames.org Copyright (C) 2011 Maciej Kaczkowski / keit.co This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. } unit mvGeoNames; interface uses SysUtils, Classes, StrUtils, mvTypes, mvDownloadEngine; type TNameFoundEvent = procedure (const AName: string; const ADescr: String; const ALoc: TRealPoint) of object; TStringArray = array of string; TResRec = record Name: String; Descr: String; Loc: TRealPoint; end; { TMVGeoNames } TMVGeoNames = class(TComponent) private FLocationName: string; FInResTable: Boolean; FInDataRows: Boolean; FNamePending: Boolean; FLongitudePending: Boolean; FLatitudePending: Boolean; FCol: Integer; FCountry: String; FSmall: Boolean; FFirstLocation: TResRec; FFoundLocation: TResRec; FOnNameFound: TNameFoundEvent; procedure FoundTagHandler(NoCaseTag, ActualTag: string); procedure FoundTextHandler(AText: String); function Parse(AStr: PChar): TRealPoint; // function RemoveTag(const str: String): TStringArray; public function Search(ALocationName: String; ADownloadEngine: TMvCustomDownloadEngine): TRealPoint; published property LocationName: string read FLocationName; property OnNameFound : TNameFoundEvent read FOnNameFound write FOnNameFound; end; implementation uses FastHtmlParser; const SEARCH_URL = 'http://geonames.org/search.html?q=%s'; //&country=%s'; function CleanLocationName(x: string): string; var i: Integer; begin Result := ''; for i := 1 to Length(x) do begin if x[i] in ['A'..'Z', 'a'..'z', '0'..'9'] then Result := Result + x[i] else Result := Result + '+' end; end; { TMVGeoNames } procedure TMvGeoNames.FoundTagHandler(NoCaseTag, ActualTag: String); begin if not FInResTable and (NoCaseTag = '