Sign in Join
Wiki copytemporary

LazMapViewer: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
1-<figure>
2-<img src="lazmapviewer.png" title="lazmapviewer.png" />
3-<figcaption>lazmapviewer.png</figcaption>
4-</figure>
1+![](/wiki-images/6/61/Lazmapviewer.png)
52
63## About
74
85**LazMapViewer** is a component for embedding maps obtained from the internet, such as Google maps or OpenStreetView, into a Lazarus form.
96
107The initial version of the package was written by Maciej Kaczkowski and later improved by members of the Lazarus forum. The package is currently maintained by Werner Pamler (wp_xxyyzzz-at-gmx-dot-net).
118
129License: Modified LGPL (with linking exception, like Lazarus LCL).
1310
1411## Download and Installation
1512
1613**Development version**
1714
1815Use an SVN client to download the current trunk version from <svn://svn.code.sf.net/p/lazarus-ccr/svn/components/lazmapviewer>. Alternatively download the zipped snapshot from <https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/lazmapviewer/> and unzip it to some folder.
1916
2017**Release version**
2118
2219Occasionally, release versions are made available via the [[Online Package Manager]] for easy one-click-installation directly from Lazarus.
2320
2421**Installation**
2522
2623In Lazarus, go to "Package" \> "Open Package File .lpk". Navigate to the folder with the LazMapViewer sources, and select `lazmapviewerpkg.lkp`. Click "Compile", then "Use" \> "Install". This will rebuild the IDE (it may take some time). When the process is finished the IDE will restart, and you'll find the MapViewer in the palette **Misc**.
2724
2825There are optional, supporting packages to extend the basic functionality. They must be installed in the same way, after `lazmapviewerpkg.lpk`.
2926
3027| Package file name | Contained components | Purpose |
3128|----|----|----|
3229| lazmapviewerpkg.lpk | TMapView | Main component to display maps |
3330| | TMvGeoNames | Access to geo coordinates of cities |
3431| | TMvDEFpc | Default download engine using the internal fpc routines |
3532| lazmapviewer_synapse.lpk | TMvDESynapse | Alternative download engine based on the Synapse library |
3633| lazmapviewer_rgbgraphics.lpk | TMvRGBGraphicsDrawingEngine | Alternative drawing engine based on the RGBGraphics package |
3734| lazmapviewer_bgra.lpk | TMvBGRADrawingEngine | Alternative drawing engine based on the BGRABitmap package |
3835
3936**Requirements**
4037
4138Release v0.2.6 was tested successfully with the following tool combinations: Laz/main + FPC/main, Laz/main + FPC/fixes, Laz 3.0 + FPC 3.2.2, Laz 2.0.8 + FPC 3.0.4, Laz 1.6.4 + FPC 3.0.2 on Windows, with Laz 3.0 + FPC 3.2.2 on Linux Mint gtk2/gtk3/qt5, and with Laz/main + FPC 3.2.2 on MacOS cocoa.
4239
4340## The Main Map Viewer: TMapView
4441
4542### Getting Started
4643
4744Here is a short tutorial to create your first map.
4845
4946#### Preparation
5047
5148- Drop a `TMapView` component on the form and size it as needed. The component is on the *Misc* tab of the Lazarus component palette.
5249- Add this handler for the form's `OnShow` or `OnActivate` event and set the `Active` property of the `MapView` component to `true`; in principle, this should be possible also in the object inspector, however, does not work at the time of this writing.
5350
5451``` Pascal
5552procedure TForm1.FormActivate(Sender: TObject);
5653begin
5754 MapView1.Active := true;
5855end;
5956```
6057
6158- That's all. Compile, run and see your fist map!
6259- In the background the `MapView` component has established an internet connection to the default map provider and downloaded the default map. The maps are delivered as a series of **tiled images** at given size, usually 256x256 pixels, and usually in png format. They are stored in a cache directory (property `CachePath`) and used primarily to reduce internet traffic; only when an image is not found another download from the internet is triggered again.
6360
6461#### Magnification
6562
6663- The map images are provided in different magnifications depending on the `Zoom` level of the `MapView`. Each step in `Zoom` level corresponds to doubling the magnification. The maximum `Zoom` level for most map providers is 18 -- this means that the most detailed maps cover a fraction of `1/2^18` of the earth circumference, about 150 m.
6764- So, if you want to see **more details** you must increase the `Zoom` value of the `MapView`. You can enter the requested value in the Object Inspector, or add a `TScrollbar` or `TTrackbar` to the form to change the magnfication interactively by using the following simple `OnChange` event handler (set the `Max` of the bar to, say, 18:
6865
6966``` Pascal
7067procedure TForm1.TrackBar1Change(Sender: TObject);
7168begin
7269 MapView1.Zoom := TrackBar1.Position;
7370end;
7471```
7572
7673- Alternatively, zooming can also be achieved by rotating the **mouse wheel**.
7774
7875#### Location
7976
8077- By default the **center of the map** is the intersection of the 0-degree meridian with the equator - which is a bit off of the coast of western Africa. In order to focus onto a different location you must specify its longitude and latitude in the `Center` property of the `MapView`. This is a `TRealPoint` record having the longitude and latitude in the `Lon` and `Lat` record elements.
8178- Suppose we want to zoom into Manhattan. Use your favorite search engine to determine the geo coordinates of Manhattan: Longitude = -73.985130°, Latitude = 40.758896°. Alternatively you can also use the TGeoNames component which comes with the LazMapViewer package and provides access to a database of the geo coordinates of a huge number of locations via internet.
8279
8380``` Pascal
8481procedure TForm1.FormActivate(Sender: TObject);
8582var
8683 P: TRealPoint;
8784begin
8885 MapView1.Active := true;
8986 P.Lon := -73.985130;
9087 P.Lat := 40.758896;
9188 MapView1.Center := P;
9289end;
9390```
9491
9592- In addition to specifying the location numerically the you can also change location by **dragging the map with the mouse**. Just press the left mouse button and slowly move the mouse in the direction where you want to see more - the map will follow. But you should be aware that usually neighboring maps will have to be loaded from the internet, and this makes the entire action a bit sluggish.
9693
9794### Basic Documentation
9895
99-<figure>
100-<img src="tmapview_200.png" title="tmapview_200.png" />
101-<figcaption>tmapview_200.png</figcaption>
102-</figure>
96+![](/wiki-images/b/bf/Tmapview_200.png)
10397
10498#### Properties
10599
106100These are the main properties of the `TMapView` component:
107101
108102- `Active (boolean)`: must be set to `true` before the `MapView` component can display maps.
109103- `CacheOnDisk (boolean)`: when set to `true` (default) dowloaded map tiles are stored in a directory to reduce internet traffic and for faster access. It is not recommended to turn this property off. The cache is not deleted automatically.
110104- `CachePath (string)`: name of the directory in which downloaded map images are buffered.
111105- `DownloadEngine (TMvCustomDownloadEngine)`: By default, the `TFPHttpClient` is employed to download the images from the map servers. If a different download engine is required the corresponding component can be hooked to this property. The standard installation of the *LazMapViewer* package contains the default `TMvDEFPC` downloader (based on FPC's `TFPHttpClient`) and the `TMvDESynapse` based on the *Synapse* library).
112106- `DrawingEngine (TMvCustomDrawingEngine)`: Painting of the tiled images is a speed-critical task. By default, this is done using routines from the *IntfGraphics* unit; the corresponding drawing engine is in the `TMvInfGraphicsDrawingEngine` class. However, it is possible to provide a different drawing engine here. The standard installation of *LazMapViewer* comes with the alternative `TMvRGBGraphicsDrawingEngine` which is based on the *RGBGraphics* package, and with the `TMvBGRADrawingEngine` utilizing the *BGRABitmap* package.
113107- `MapProvider (string)`: This string identifies the provider from which the maps are downloaded. Built-in providers allow to choose between *OpenStreetMaps*, *GoogleMaps*, *Virtual Earth*, *Yandex* etc. Details are given in section Map Providers.
114108- `Options = [mvoMouseDragging, mvoMouseZooming]`: Allows to disable dragging of the map with the mouse and zooming with the mouse wheel when the corresponding option is removed from the set (in v0.2.7 and newer). Default: both options active.
115109- `UseThreads (boolean)`: When set to `true` downloading and drawing of maps is delegated to several threads in order to achieve a smoother response. It is not recommended to turn this property off.
116110- `Zoom (integer)`: Magnfication of the map: 0 = coarsest magnification, earth view, 17 or 18 = highest magnification. Each zoom step results in doubling of the magnfication factor.
117111- `ZoomToCursor (boolean)`: When this is `true` zooming occurs relative to the mouse position, otherwise to the center of the map. This feature is interesting for zooming with the mouse wheel.
118112
119113Here are properties related to overlayed GPS objects (points of interest, tracks):
120114
121115- `GPSItems: TGPSObjectList`: list of GPS objects assigned to the MapView See below for details.
122116- `DefaultTrackColor: TColor`, `DefaultTrackWidth: Integer`: the default color and line width, respectively, of overlayed tracks. See below for details.
123117- `POIImage: TBitmap`: bitmap which will be overlayed to identify a "point of interest" (POI).
124118- `POITextBgColor: TColor`: background color of the overlayed text describing a point of interest. Turn off the text background by selecting `clNone`.
125119
126120#### Events
127121
128122- `OnCenterMove`: fires whenever the `Center` of the `MapView` have been changed.
129123- `OnChange`: fires whenever the `Center`, size or `Zoom` factor of the `MapView` change.
130124- `OnDrawGpsPoint`: see below
131125- `OnZoomChange`: fires whenever the `Zoom` factor of the `MapView` changes.
132126- `OnMouseDown, OnMouseEnter, OnMouseLeave, OnMouseMove, OnMouseUp`: standard mouse events.
133127
134128#### Main methods
135129
136130- `procedure GetMapProviders(lstProviders: TStrings)`: Returns in `lstProviders` the names of all registered map providers. When one of these strings is assigned to the `MapProvider` property of the `MapVieew` the servers of the corresponding provider will become the source of the displayed maps.
137131- `function GetVisibleArea: TRealArea`: returns the top/left and bottom/right corner points of the displayed rectangle in geo coordinates. `TRealArea` is a record consisting of the `TRealPoint` records `TopLeft` and `BottomRight`.
138132- `function LonLatToScreen(aPt: TRealPoint): TPoint`: maps a geo point (longitude, latitude) to screen pixels (relative to the `TMapView` instance).
139133- `function ScreenToLonLat(aPt: TPoint): TRealPoint`: maps a the coordinates of a screen pixel (relative to the `MapView` instance) to geo coordinates (longitude, latitude). Here is an example how the geo coordinates of the mouse cursor can be displayed in two labels by means of the `OnMouseMove` event of the `MapView`:
140134
141135``` Pascal
142136uses
143137 mvTypes, // for TRealPoint
144138 mvEngine; // for LonToStr() and LatToStr() funtions
145139
146140procedure TForm1.MapView1MouseMove(Sender: TObject; Shift: TShiftState;
147141 X, Y: Integer);
148142var
149143 P: TRealPoint;
150144begin
151145 P := MapView1.ScreenToLonLat(Point(X, Y));
152146 Label1.Caption := 'Longitude: ' + LonToStr(P.Lon, true);
153147 Label2.Caption := 'Latitude: ' + LatToStr(P.Lat, true);
154148end;
155149```
156150
157151- `procedure SaveToFile(AClass: TRasterImageClass; const AFileName: String)`: Save the currently displayed map as bitmap of the given class to a file. Example for saving to a jpg image:
158152
159153``` Pascal
160154procedure TForm1.Button1Click(Sender: TObject);
161155begin
162156 MapView1.SaveToFile(TJpegImage, 'mapview.jpg');
163157end;
164158```
165159
166160- `procedure SaveToStream(AClass: TRasterImageClass; AStream: TStream)`: Similar to `SaveToFile`, but output is not in a file, but in the stream provided.
167161- `function SaveToImage(AClass: TRasterImageClass): TRasterImage`: creates an instance of the given image class and writes the currently visible view port image to it.
168162- `procedure CenterOnObj(obj: TGPSObj)`: Centers the map on the provided GPS object. More on GPS objects below.
169163- `procedure ZoomOnArea(const aArea: TRealArea)`: Adjusts the `Zoom` level such that the given area is completely shown and fills the component bounds as much as possible.
170164- `procedure ZoomOnObj(obj: TGPSObj)`: Adjusts the `Zoom` level such that the given GPS object is completely seen at highest magnification. More about GPS objects below.
171165
172166### Map Providers
173167
174168The `MapView` component can display maps from various providers. To activate a given provider its name must be specified in the `MapProvider` property of the component.
175169
176170Here is a list of the names of the built-in map providers:
177171
178172- OpenStreetMap Mapnik
179173- OpenStreetMap Wikipedia
180174- OpenStreetMap Sputnik
181175- OpenStreetMap.fr Hot
182176- OpenStreetMap.fr Cycle Map
183177- Open Topo Map
184178- Google Maps
185179- Google Satellite
186180- Yandex.Maps
187181- Yandex.Maps Satellite
188182- Virtual Earth Bing
189183- Virtual Earth Aerial
190184- Virtual Earth Hybrid
191185
192186The following providers require an API key to access their service. The API key can be obtained by registering at the provider sites. Usually the API keys are free, however, a charge may be required for commercial usage - please see the details on the provider sites. The strings received as API keys must be stored in global variables of your application.
193187
194188- Registration at <https://www.thunderforest.com/docs/apikeys/>, store API key in the variable `ThunderForest_ApiKey`:
195189 - Open Cycle Map
196190 - OpenStreetMap Transport
197191- Registration at <https://developer.here.com/?create=Freemium-Basic&keepState=true&step=account>, store the received APP ID and APP CODE in the variables `HERE_AppID` and `HERE_AppCode`, respectively:
198192 - Here WeGo Map
199193 - Here WeGo Grey Map
200194 - Here WeGo Reduced Map
201195 - Here WeGo Transit Map
202196 - Here WeGo POI Map
203197 - Here WeGo Pedestrian Map
204198 - Here WeGo DreamWorks Map
205199- Registration at <https://home.openweathermap.org/users/sign_up>, store the API Key in variable `OpenWeatherMap_ApiKey`:
206200 - OpenWeatherMap Clouds
207201 - OpenWeatherMap Precipitation
208202 - OpenWeatherMap Pressure
209203 - OpenWeatherMap Temperature
210204 - OpenWeatherMap Wind
211205
212206Please respect the license requirements of the map providers.
213207
214208### GPS Objects
215209
216210The public `TMapView` property `GPSItems` collects data on points of interest and tracks to be overlayed on the map. The common data type of these overlay items is
217211
218212``` Pascal
219213type
220214 TGPSObj = class
221215 ...
222216 public
223217 destructor Destroy; override;
224218 property Name: String read FName write FName;
225219 property ExtraData: TObject read FExtraData write SetExtraData;
226220 property IdOwner: Integer read FIdOwner;
227221 property BoundingBox: TRealArea read GetBoundingBox write SetBoundingBox;
228222 end;
229223```
230224
231225The `Name` can be displayed near the item in the map.
232226
233227`ExtraData` can be used freely, for example to define the color of a track. An example how this could be done is found in unit `mvExtraData`, classes `TDrawingExtraData` and `TTrackExtraData`.
234228
235229`IdOwner` is the ID of the owner TGPSObj instance to which the current item belongs. `BoundingBox` gives the geo coordinates of the top/left and bottom/right corner points of the rectangle containing all points of the item.
236230
237231#### Points
238232
239233A special `TGPSObj` item is a `TGPSPoint`, for example a scenic "Point-of-Interest" (POI), a way point along a hiking path etc.
240234
241235``` Pascal
242236 TGPSPoint = class(TGPSObj)
243237 public
244238 constructor Create(ALon,ALat: double; AEle: double=NO_ELE; ADateTime: TDateTime=NO_DATE);
245239 class function CreateFrom(aPt: TRealPoint): TGPSPoint;
246240
247241 function HasEle: boolean;
248242 function HasDateTime: Boolean;
249243 function DistanceInKmFrom(OtherPt: TGPSPoint; UseEle: boolean=true): double;
250244
251245 property Lon: Double read GetLon;
252246 property Lat: Double read GetLat;
253247 property Ele: double read FEle;
254248 property DateTime: TDateTime read FDateTime;
255249 property RealPoint: TRealPoint read FRealPt;
256250 end;
257251```
258252
259253In its constructor, the geo coordinate longitude and latitude must be specified. They are also available as read-only properties `Lon` and `Lat`. Optional parameters are the elevation of the point (property `Ele` as well as some date/time information (property `DateTime`), for example the date when this point was visited. A special function, `DistanceInKmFrom`, is available to calculate the on-earth distance from another GPS point.
260254
261255#### Tracks
262256
263257The second important `TGPSObj` descendant is `TGPSTrack` which stores the points along a path, for example points visited on a trip or a hike. Each point is a instance of the `TGPSPoint` class, and the individual points are collected by the list `Points`. Again, there is a `DataTime` property usable for example to hold the date of the hike. Function `TrackLengthInKm` calculates the length of the entire path with the points being connected by straight line segments.
264258
265259``` Pascal
266260type
267261 TGPSTrack = class(TGPSObj)
268262 private
269263 FDateTime: TDateTime;
270264 FPoints: TGPSPointList;
271265 function GetDateTime: TDateTime;
272266 public
273267 constructor Create;
274268 destructor Destroy; override;
275269
276270 procedure GetArea(out Area: TRealArea); override;
277271 function TrackLengthInKm(UseEle: Boolean=true): double;
278272
279273 property Points: TGPSPointList read FPoints;
280274 property DateTime: TDateTime read GetDateTime write FDateTime;
281275 end;
282276```
283277
284278#### List of GPS Objects
285279
286280The property `GpsItems` of the `TMapView` component is the main class collecting all the GPS objects. It is an instance of the `TGPSObjectList`:
287281
288282``` Pascal
289283type
290284 TGPSObjectList = class(TGPSObj)
291285 ...
292286 constructor Create;
293287 destructor Destroy; override;
294288
295289 Procedure Clear(OwnedBy: integer);
296290 procedure ClearExcept(OwnedBy: integer; const ExceptLst: TIdArray; out Notfound: TIdArray);
297291 procedure GetArea(out Area: TRealArea); override;
298292 function GetObjectsInArea(const Area: TRealArea): TGPSObjList;
299293 function GetIdsArea(const Ids: TIdArray; AIdOwner: integer): TRealArea;
300294
301295 function Add(aItem: TGpsObj; AIdOwner: integer): integer;
302296 procedure DeleteById(const Ids: Array of integer);
303297
304298 procedure BeginUpdate;
305299 procedure EndUpdate;
306300
307301 property Count: integer read GetCount;
308302 property Items[AIndex: Integer]: TGpsObj read GetItem; default;
309303
310304 property OnModified: TModifiedEvent read FOnModified write FOnModified;
311305 end;
312306```
313307
314308Objects can be added to the list by calling the `Add` method. Since each addition is accompanied by a repaint of the `MapView` you should call `BeginUpdate` before and `EndUpdate` after adding the objects. Every added object must be assigned to an arbitrary ID which is used to group the objects.
315309
316310Method `DeleteByID` deletes all objects sharing the same IDE. `Clear`, on the other hand, clears all the objects which are owned by object having the specified ID. An extension is `ClearExcept` which does the same but skips IDs listed in the `ExceptLst` array.
317311
318312`GetObjectsInArea` creates a TFPObjectlist (of type `TGpsObjList` here) with all the objects enclosed by the given rectangle (`Area`). `GetIDsArea`, conversely, returns the rectangle enclosing all the objects with the IDs listed in parameter `IDs` (which is a simple array here).
319313
320314#### Example: Adding a Point of Interest
321315
322316Suppose you want to mark a special point in the map by a mouse click and identify it with some descriptive text. Write a handler for the OnMouseUp event in which you query the description and then take the pixel coordinates of the clicked point, convert it to geo coordinates and create a `TGpsPoint` from it which you add to the `GpsItems` of the `MapView`:
323317
324318``` Pascal
325319uses
326320 mvTypes, mvGPSObj;
327321
328322const
329323 _POI_ = 10;
330324
331325procedure TForm1.MapView1MouseUp(Sender: TObject; Button: TMouseButton;
332326 Shift: TShiftState; X, Y: Integer);
333327var
334328 pt: TRealPoint;
335329 gpsPt: TGpsPoint;
336330 ptName: String;
337331begin
338332 ptName := '';
339333 if InputQuery('Point of Interest', 'Enter name:', ptName) then
340334 begin
341335 pt := MapView1.ScreenToLonLat(Point(X, Y));
342336 gpsPt := TGpsPoint.CreateFrom(pt, NO_ELE, Now() );
343337 gpsPt.Name := ptName;
344338 Mapview1.GPSItems.Add(gpsPt, _POI_);
345339 end;
346340end;
347341```
348342
349343In this example the constant `_POI_` is used as ID of the added point. By default, the point is drawn as a red cross, the name is drawn underneath it. You can highlight the text by changing its background color in property `POITextBgColor` of the `MapView`. You can also replace the red cross by an arbitrary bitmap which must be loaded into the `POIImage` property (the folder *example* of the LazMapViewer installation contains a ready-to-use pin-cushion icon).
350344
351345There is also an event, `OnDrawGpsPoint`, which can be used to replace the entire labeling process by custom routines. The event has the `GpsPoint` as parameter. Drawing style can be defined based on the data stored in the `GpsPoint`. The other event parameter is the `DrawingEngine` which provides methods for drawing; it will be explained below. Here is an example in which the added Point-of-Interest is drawn by a blue circle and labeled by a large bold font:
352346
353347``` Pascal
354348procedure TForm1.MapView1DrawGpsPoint(Sender: TObject;
355349 ADrawer: TMvCustomDrawingEngine; APoint: TGpsPoint);
356350const
357351 R = 8;
358352var
359353 p: TPoint;
360354begin
361355 // Screen coordinates of the GPS point
362356 p := MapView1.LonLatToScreen(APoint.RealPoint);
363357
364358 // Draw a blue circle
365359 ADrawer.PenColor := clBlack;
366360 ADrawer.BrushColor := clBlue;
367361 ADrawer.BrushStyle := bsSolid;
368362 ADrawer.Ellipse(p.X-R, p.Y-R, P.X+R, p.Y+R);
369363
370364 // Draw the point label
371365 ADrawer.BrushStyle := bsClear;
372366 ADrawer.FontName := 'SegoeUI';
373367 ADrawer.FontSize := 16;
374368 ADrawer.FontStyle := [fsBold];
375369 ADrawer.TextOut(
376370 p.X - ADrawer.TextWidth(APoint.Name) div 2,
377371 p.Y + R + 4,
378372 APoint.Name
379373 );
380374end;
381375```
382376
383377## Finding Geo Locations: TMvGeoNames
384378
385379`TMvGeoNames` is a component which searches the geo coordinates (longitude, latitude) of many cities or other locations in the world. Using the download engine of the `MapView` component it sends a query to the site <http://geonames.org/search.html> and analyzes the returned html string.
386380
387-<figure>
388-<img src="tmvgeonames_200.png" title="tmvgeonames_200.png" />
389-<figcaption>tmvgeonames_200.png</figcaption>
390-</figure>
381+![](/wiki-images/c/cb/Tmvgeonames_200.png)
391382
392383### Getting Started
393384
394385- Assuming that you already have set up an application for the `TMapView` component as described above, you simply drop a `TMvGeoNames` component on the form; it is located next to the `TMapView` icon in the *Misc* component palette.
395386- Add a button which is supposed to trigger the search.
396387- Write an `OnClick` handler for the button which calls the `TMvGeoNames` method `Search`. Enter the search destination as first parameter, and the download engine to be used as second parameter. The function returns the found longitude and latitude as a `TRealPoint` record which can be passed immediately to the `Center` property of the `MapView` component. This way, the viewer can immediately jump to the found location:
397388
398389``` pascal
399390procedure TForm1.Button1Click(Sender: TObject);
400391begin
401392 MapView1.Center := MvGeoNames1.Search('Grand Canyon National Park', MapView1.DownloadEngine);
402393end;
403394```
404395
405396### Documentation
406397
407398#### Methods
408399
409400- `function Search(ALocationName: String; ADownloadEngine: TMvCustomDownloadEngine): TRealPoint`: searches the requested location using the specified download engine. Return value are the geo coordinates of the location given as a `TRealPoint`. The search returns also locations with similar names, however, they must be extracted by handling the `OnNameFound` event.
410401
411402#### Properties
412403
413404- `LocationName: string`: Is the name of the (first) found location as listed by the *geonames* site.
414405
415406#### Events
416407
417408- `OnNameFound`: This event is triggered while the received response of the *geonames* server is being analyzed. The html string usually contains a variety of locations. Whenver a location has been extracted from the received string the event is fired and tells the name, a description, and the longitude/latitude `TRealPoint` record for this location. Handling this event makes it possible to list all the found locations for example in a combobox or listbox to give the user the opportunity to select any one of them:
418409
419410``` pascal
420411type
421412 TGeoLocation = class
422413 Name: String;
423414 Descr: String;
424415 Coords: TRealPoint;
425416 end;
426417
427418procedure TForm1.MVGeoNames1NameFound(const AName: string;
428419 const ADescr: String; const ALoc: TRealPoint);
429420var
430421 loc: TGeoLocation;
431422begin
432423 loc := TGeoLocation.Create;
433424 loc.Name := AName;
434425 loc.Descr := ADescr;
435426 loc.Coords := ALoc;
436427 ComboBox1.Items.AddObject(AName, loc);
437428end;
438429```
439430
440431---
441432*From the Free Pascal wiki, page "LazMapViewer", as it stood on 2024-01-29 after a change by Wp, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history