getting location via GPS on android with Processing
up vote
0
down vote
favorite
im working on a small app that needs access to GPS so that i can track my position.
However i pasted some code that i can use to check if it works. I will rewrite it later so that it can be adjusted but for now i just want to try it.
BUT when i execute the app all paramaters stay the way they were initialized.
I do have all permissions enabled and also GPS enabled. Even went outside to check if it works, but it will always stay the same.
after the app asks if i allow the app to use gps service everything is executed correctly. It returns positive for location tracking.
Here is the code: (it can also be found under here: https://github.com/codeanticode/processing-android-tutorials/blob/master/location_permissions/ex1_gps/ex1_gps.pde)
/*****************************************************************************************
Android Processing GPS example
Query the phone's GPS and display the data on the screen
Rolf van Gelder - v 22/02/2011 - http://cage.nl :: http://cagewebdev.com :: info@cage.nl
Check the ACCESS_FINE_LOCATION permission in Sketch Permissions!
*****************************************************************************************/
// Import needed Android libs
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.provider.Settings;
import android.os.Bundle;
import android.Manifest;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
// Set up the variables for the LocationManager and LocationListener
LocationManager locationManager;
MyLocationListener locationListener;
// Variables to hold the current GPS data
float currentLatitude = 0;
float currentLongitude = 0;
float currentAccuracy = 0;
String currentProvider = "";
boolean hasLocation = false;
void setup () {
fullScreen();
orientation(PORTRAIT);
textFont(createFont("SansSerif", 26 * displayDensity));
textAlign(CENTER, CENTER);
requestPermission("android.permission.ACCESS_FINE_LOCATION", "initLocation");
}
void draw() {
background(0);
if (hasPermission("android.permission.ACCESS_FINE_LOCATION")) {
text("Latitude: " + currentLatitude + "n" +
"Longitude: " + currentLongitude + "n" +
"Accuracy: " + currentAccuracy + "n" +
"Provider: " + currentProvider, 0, 0, width, height);
} else {
text("No permissions to access location", 0, 0, width, height);
}
}
void initLocation(boolean granted) {
if (granted) {
Context context = getContext();
locationListener = new MyLocationListener();
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
hasLocation = true;
} else {
hasLocation = false;
}
}
// Class for capturing the GPS data
class MyLocationListener implements LocationListener {
public void onLocationChanged(Location location) {
currentLatitude = (float)location.getLatitude();
currentLongitude = (float)location.getLongitude();
currentAccuracy = (float)location.getAccuracy();
currentProvider = location.getProvider();
}
public void onProviderDisabled (String provider) {
currentProvider = "";
}
public void onProviderEnabled (String provider) {
currentProvider = provider;
}
public void onStatusChanged (String provider, int status, Bundle extras) {
}
}
java permissions location processing android-gps
add a comment |
up vote
0
down vote
favorite
im working on a small app that needs access to GPS so that i can track my position.
However i pasted some code that i can use to check if it works. I will rewrite it later so that it can be adjusted but for now i just want to try it.
BUT when i execute the app all paramaters stay the way they were initialized.
I do have all permissions enabled and also GPS enabled. Even went outside to check if it works, but it will always stay the same.
after the app asks if i allow the app to use gps service everything is executed correctly. It returns positive for location tracking.
Here is the code: (it can also be found under here: https://github.com/codeanticode/processing-android-tutorials/blob/master/location_permissions/ex1_gps/ex1_gps.pde)
/*****************************************************************************************
Android Processing GPS example
Query the phone's GPS and display the data on the screen
Rolf van Gelder - v 22/02/2011 - http://cage.nl :: http://cagewebdev.com :: info@cage.nl
Check the ACCESS_FINE_LOCATION permission in Sketch Permissions!
*****************************************************************************************/
// Import needed Android libs
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.provider.Settings;
import android.os.Bundle;
import android.Manifest;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
// Set up the variables for the LocationManager and LocationListener
LocationManager locationManager;
MyLocationListener locationListener;
// Variables to hold the current GPS data
float currentLatitude = 0;
float currentLongitude = 0;
float currentAccuracy = 0;
String currentProvider = "";
boolean hasLocation = false;
void setup () {
fullScreen();
orientation(PORTRAIT);
textFont(createFont("SansSerif", 26 * displayDensity));
textAlign(CENTER, CENTER);
requestPermission("android.permission.ACCESS_FINE_LOCATION", "initLocation");
}
void draw() {
background(0);
if (hasPermission("android.permission.ACCESS_FINE_LOCATION")) {
text("Latitude: " + currentLatitude + "n" +
"Longitude: " + currentLongitude + "n" +
"Accuracy: " + currentAccuracy + "n" +
"Provider: " + currentProvider, 0, 0, width, height);
} else {
text("No permissions to access location", 0, 0, width, height);
}
}
void initLocation(boolean granted) {
if (granted) {
Context context = getContext();
locationListener = new MyLocationListener();
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
hasLocation = true;
} else {
hasLocation = false;
}
}
// Class for capturing the GPS data
class MyLocationListener implements LocationListener {
public void onLocationChanged(Location location) {
currentLatitude = (float)location.getLatitude();
currentLongitude = (float)location.getLongitude();
currentAccuracy = (float)location.getAccuracy();
currentProvider = location.getProvider();
}
public void onProviderDisabled (String provider) {
currentProvider = "";
}
public void onProviderEnabled (String provider) {
currentProvider = provider;
}
public void onStatusChanged (String provider, int status, Bundle extras) {
}
}
java permissions location processing android-gps
Have you tried looking in the logs for errors?
– Kevin Workman
Nov 7 at 20:38
there are no errors. Everything runs smoothly except its not getting the data. It recognizes that gps permissions exist and gps access is allowed
– Oliver Tworkowski
Nov 7 at 21:44
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
im working on a small app that needs access to GPS so that i can track my position.
However i pasted some code that i can use to check if it works. I will rewrite it later so that it can be adjusted but for now i just want to try it.
BUT when i execute the app all paramaters stay the way they were initialized.
I do have all permissions enabled and also GPS enabled. Even went outside to check if it works, but it will always stay the same.
after the app asks if i allow the app to use gps service everything is executed correctly. It returns positive for location tracking.
Here is the code: (it can also be found under here: https://github.com/codeanticode/processing-android-tutorials/blob/master/location_permissions/ex1_gps/ex1_gps.pde)
/*****************************************************************************************
Android Processing GPS example
Query the phone's GPS and display the data on the screen
Rolf van Gelder - v 22/02/2011 - http://cage.nl :: http://cagewebdev.com :: info@cage.nl
Check the ACCESS_FINE_LOCATION permission in Sketch Permissions!
*****************************************************************************************/
// Import needed Android libs
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.provider.Settings;
import android.os.Bundle;
import android.Manifest;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
// Set up the variables for the LocationManager and LocationListener
LocationManager locationManager;
MyLocationListener locationListener;
// Variables to hold the current GPS data
float currentLatitude = 0;
float currentLongitude = 0;
float currentAccuracy = 0;
String currentProvider = "";
boolean hasLocation = false;
void setup () {
fullScreen();
orientation(PORTRAIT);
textFont(createFont("SansSerif", 26 * displayDensity));
textAlign(CENTER, CENTER);
requestPermission("android.permission.ACCESS_FINE_LOCATION", "initLocation");
}
void draw() {
background(0);
if (hasPermission("android.permission.ACCESS_FINE_LOCATION")) {
text("Latitude: " + currentLatitude + "n" +
"Longitude: " + currentLongitude + "n" +
"Accuracy: " + currentAccuracy + "n" +
"Provider: " + currentProvider, 0, 0, width, height);
} else {
text("No permissions to access location", 0, 0, width, height);
}
}
void initLocation(boolean granted) {
if (granted) {
Context context = getContext();
locationListener = new MyLocationListener();
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
hasLocation = true;
} else {
hasLocation = false;
}
}
// Class for capturing the GPS data
class MyLocationListener implements LocationListener {
public void onLocationChanged(Location location) {
currentLatitude = (float)location.getLatitude();
currentLongitude = (float)location.getLongitude();
currentAccuracy = (float)location.getAccuracy();
currentProvider = location.getProvider();
}
public void onProviderDisabled (String provider) {
currentProvider = "";
}
public void onProviderEnabled (String provider) {
currentProvider = provider;
}
public void onStatusChanged (String provider, int status, Bundle extras) {
}
}
java permissions location processing android-gps
im working on a small app that needs access to GPS so that i can track my position.
However i pasted some code that i can use to check if it works. I will rewrite it later so that it can be adjusted but for now i just want to try it.
BUT when i execute the app all paramaters stay the way they were initialized.
I do have all permissions enabled and also GPS enabled. Even went outside to check if it works, but it will always stay the same.
after the app asks if i allow the app to use gps service everything is executed correctly. It returns positive for location tracking.
Here is the code: (it can also be found under here: https://github.com/codeanticode/processing-android-tutorials/blob/master/location_permissions/ex1_gps/ex1_gps.pde)
/*****************************************************************************************
Android Processing GPS example
Query the phone's GPS and display the data on the screen
Rolf van Gelder - v 22/02/2011 - http://cage.nl :: http://cagewebdev.com :: info@cage.nl
Check the ACCESS_FINE_LOCATION permission in Sketch Permissions!
*****************************************************************************************/
// Import needed Android libs
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.provider.Settings;
import android.os.Bundle;
import android.Manifest;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
// Set up the variables for the LocationManager and LocationListener
LocationManager locationManager;
MyLocationListener locationListener;
// Variables to hold the current GPS data
float currentLatitude = 0;
float currentLongitude = 0;
float currentAccuracy = 0;
String currentProvider = "";
boolean hasLocation = false;
void setup () {
fullScreen();
orientation(PORTRAIT);
textFont(createFont("SansSerif", 26 * displayDensity));
textAlign(CENTER, CENTER);
requestPermission("android.permission.ACCESS_FINE_LOCATION", "initLocation");
}
void draw() {
background(0);
if (hasPermission("android.permission.ACCESS_FINE_LOCATION")) {
text("Latitude: " + currentLatitude + "n" +
"Longitude: " + currentLongitude + "n" +
"Accuracy: " + currentAccuracy + "n" +
"Provider: " + currentProvider, 0, 0, width, height);
} else {
text("No permissions to access location", 0, 0, width, height);
}
}
void initLocation(boolean granted) {
if (granted) {
Context context = getContext();
locationListener = new MyLocationListener();
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
hasLocation = true;
} else {
hasLocation = false;
}
}
// Class for capturing the GPS data
class MyLocationListener implements LocationListener {
public void onLocationChanged(Location location) {
currentLatitude = (float)location.getLatitude();
currentLongitude = (float)location.getLongitude();
currentAccuracy = (float)location.getAccuracy();
currentProvider = location.getProvider();
}
public void onProviderDisabled (String provider) {
currentProvider = "";
}
public void onProviderEnabled (String provider) {
currentProvider = provider;
}
public void onStatusChanged (String provider, int status, Bundle extras) {
}
}
java permissions location processing android-gps
java permissions location processing android-gps
asked Nov 7 at 20:33
Oliver Tworkowski
204
204
Have you tried looking in the logs for errors?
– Kevin Workman
Nov 7 at 20:38
there are no errors. Everything runs smoothly except its not getting the data. It recognizes that gps permissions exist and gps access is allowed
– Oliver Tworkowski
Nov 7 at 21:44
add a comment |
Have you tried looking in the logs for errors?
– Kevin Workman
Nov 7 at 20:38
there are no errors. Everything runs smoothly except its not getting the data. It recognizes that gps permissions exist and gps access is allowed
– Oliver Tworkowski
Nov 7 at 21:44
Have you tried looking in the logs for errors?
– Kevin Workman
Nov 7 at 20:38
Have you tried looking in the logs for errors?
– Kevin Workman
Nov 7 at 20:38
there are no errors. Everything runs smoothly except its not getting the data. It recognizes that gps permissions exist and gps access is allowed
– Oliver Tworkowski
Nov 7 at 21:44
there are no errors. Everything runs smoothly except its not getting the data. It recognizes that gps permissions exist and gps access is allowed
– Oliver Tworkowski
Nov 7 at 21:44
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
The solution:
change the "0, 0" in
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);to a "1000, 0" depending on how often you want to get your current position in this case: 1000 ms. Im not gonna talk about the second 0.also instead of using
NETWORK_PROVIDERuseGPS_PROVIDERto get your true GPS pos instead of networked pos.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
The solution:
change the "0, 0" in
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);to a "1000, 0" depending on how often you want to get your current position in this case: 1000 ms. Im not gonna talk about the second 0.also instead of using
NETWORK_PROVIDERuseGPS_PROVIDERto get your true GPS pos instead of networked pos.
add a comment |
up vote
0
down vote
The solution:
change the "0, 0" in
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);to a "1000, 0" depending on how often you want to get your current position in this case: 1000 ms. Im not gonna talk about the second 0.also instead of using
NETWORK_PROVIDERuseGPS_PROVIDERto get your true GPS pos instead of networked pos.
add a comment |
up vote
0
down vote
up vote
0
down vote
The solution:
change the "0, 0" in
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);to a "1000, 0" depending on how often you want to get your current position in this case: 1000 ms. Im not gonna talk about the second 0.also instead of using
NETWORK_PROVIDERuseGPS_PROVIDERto get your true GPS pos instead of networked pos.
The solution:
change the "0, 0" in
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);to a "1000, 0" depending on how often you want to get your current position in this case: 1000 ms. Im not gonna talk about the second 0.also instead of using
NETWORK_PROVIDERuseGPS_PROVIDERto get your true GPS pos instead of networked pos.
answered Nov 16 at 13:39
Oliver Tworkowski
204
204
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53197389%2fgetting-location-via-gps-on-android-with-processing%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Have you tried looking in the logs for errors?
– Kevin Workman
Nov 7 at 20:38
there are no errors. Everything runs smoothly except its not getting the data. It recognizes that gps permissions exist and gps access is allowed
– Oliver Tworkowski
Nov 7 at 21:44