This repository was archived by the owner on Jun 24, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +7
-16
lines changed
location_permissions/gps_example Expand file tree Collapse file tree 1 file changed +7
-16
lines changed Original file line number Diff line number Diff line change @@ -35,16 +35,17 @@ PFont androidFont;
35
35
boolean hasLocation = false ;
36
36
37
37
void setup () {
38
- size ( 480 , 640 , P2D );
39
- orientation(PORTRAIT );
38
+ fullScreen( );
39
+ orientation(PORTRAIT );
40
40
fontList = PFont . list();
41
41
androidFont = createFont (fontList[0 ], 26 , true );
42
42
textFont (androidFont);
43
+ requestPermission(" android.permission.ACCESS_FINE_LOCATION" , " initLocation" );
43
44
}
44
45
45
46
void draw () {
46
47
background (0 );
47
- if (hasLocation ) {
48
+ if (hasPermission( " android.permission.ACCESS_FINE_LOCATION " ) ) {
48
49
// Display current GPS data
49
50
text (" Latitude: " + currentLatitude, 20 , 40 );
50
51
text (" Longitude: " + currentLongitude, 20 , 75 );
@@ -55,19 +56,9 @@ void draw() {
55
56
}
56
57
}
57
58
58
- void onPermissionsGranted () {
59
- initLocation();
60
- }
61
-
62
- void initLocation () {
63
- if (checkPermission(Manifest . permission. ACCESS_FINE_LOCATION ) ||
64
- checkPermission(Manifest . permission. ACCESS_COARSE_LOCATION )) {
65
-
66
- // For 3.x versions of the mode
67
- // context = getActivity();
68
-
69
- // For 4.0+ versions of the mode
70
- Context context = surface. getContext();
59
+ void initLocation (boolean granted ) {
60
+ if (granted) {
61
+ Context context = getContext();
71
62
72
63
locationListener = new MyLocationListener ();
73
64
locationManager = (LocationManager ) context. getSystemService(Context . LOCATION_SERVICE );
You can’t perform that action at this time.
0 commit comments