1+ { declare library aLocation}
2+ uses
3+ aLocation, crt;
4+
5+ { declare type java}
6+ type
7+ map = java_util_Map;{ https://docs.oracle.com/javase/7/docs/api/java/util/Map.html}
8+ list = java_util_List; { https://docs.oracle.com/javase/7/docs/api/java/util/List.html}
9+ obj = java_lang_Object;
10+ loc = android_location_Location;
11+ { https://developer.android.com/reference/android/location/Location.html}
12+ var
13+ i: Integer;
14+ data: map; { Location data will be saved here}
15+
16+ { This method will be print data to console,
17+ include latitude, longitude,....}
18+ procedure printData (data: map);
19+ var
20+ providers: list;
21+ i: Integer;
22+ name : obj; // the name of provider
23+ info: loc; // store data of location
24+ begin
25+ { Each provider has a set of criteria under
26+ which it may be used; for example, some providers
27+ require GPS hardware and visibility to a number
28+ of satellites; others require the use of the
29+ cellular radio, or access to a specific carrier's
30+ network, or to the internet.}
31+
32+ { Returns available providers on the phone}
33+ providers := locationProviders();
34+
35+ for i := 0 to providers.size() - 1 do
36+ begin
37+ name := providers.get(i); // get name of provider in position i
38+
39+ if (data.get(name ) <> null) then // if the data of provider is exist
40+ begin
41+ cast(info, data.get(name ));
42+
43+ // print long,lat to console
44+ writeln(' getLatitude = ' , info.getLatitude());
45+ writeln(' getLongitude = ' , info.getLongitude());
46+ end ;
47+ end ;
48+ writeln;
49+ end ;
50+
51+
52+ begin
53+ { Starts collecting location data.
54+ The first parameter is minimum time between updates in milliseconds
55+ The second parameter is minimum distance between updates in meters}
56+ startLocating(100 , 10 );
57+
58+ // wait for 60 second
59+ for i := 1 to 60 do
60+ begin
61+ delay(1000 ); // wait for collect info
62+ data := readLocation(); // read data
63+ printData(data); // print data to console
64+ end ;
65+
66+ // stop collect data
67+ stopLocating();
68+ end .
0 commit comments