{ Map Viewer Geolocation Engine for geonames.org Copyright (C) 2011 Maciej Kaczkowski / keit.co License: modified LGPL with linking exception (like RTL, FCL and LCL) See the file COPYING.modifiedLGPL.txt, included in the Lazarus distribution, for details about the license. See also: https://wiki.lazarus.freepascal.org/FPC_modified_LGPL } 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, {%H-}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 = '