Real-time GPS on Android and computer ?

edited October 2015 in Android Mode

So I have recently been learning about processing. So i'm still a newbie. I have also done a project where processing is reading a CSV file with coordinates (that was made in Openpaths). I want to take this to the next level by connecting my phone (LG G2, Android) that sends real time coordinates to my computer (as long as there is internet) which you can see moving (I will later on connect that dot with grasshopper as an attractor point).

I found a script too earlier that was maybe suitable as a good start:

import android.content.Context;
import android.location.Location;
import android.location.LocationManager;
import android.location.LocationListener;
import android.location.GpsStatus.Listener;
import android.location.GpsStatus.NmeaListener; // not needed yet, but going for nmea data next!
import android.os.Bundle;

String[] fontList;
PFont androidFont;

LocationManager locationManager;
MyLocationListener locationListener;

// Variables to hold the current GPS data
float currentLatitude  = 0;
float currentLongitude = 0;
float currentAccuracy  = 0;
String currentProvider = "";

//-----------------------------------------------------------------------------------------

void setup() {
size(screenWidth, screenHeight);
background(0);
fontList = PFont.list();
androidFont = createFont(fontList[4], 35, true);
textFont(androidFont);
}

//-----------------------------------------------------------------------------------------

void draw() {
background(0);
// Display current GPS data
text("Latitude: "+currentLatitude, 20, 40);
text("Longitude: "+currentLongitude, 20, 75);
text("Accuracy: "+currentAccuracy, 20, 110);
text("Provider: "+currentProvider, 20, 145);  
}

//-----------------------------------------------------------------------------------------

void onResume() {
super.onResume();
// Build Listener
locationListener = new MyLocationListener();
// Acquire a reference to the system Location Manager
locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
}

void onPause() {
super.onPause();
}

//-----------------------------------------------------------------------------------------

// Define a listener that responds to location updates
class MyLocationListener implements LocationListener {
void onLocationChanged(Location location) {
// Called when a new location is found by the network location provider.
  currentLatitude  = (float)location.getLatitude();
  currentLongitude = (float)location.getLongitude();
  currentAccuracy  = (float)location.getAccuracy();
  currentProvider  = location.getProvider();
}
void onProviderDisabled (String provider) { 
  currentProvider = "";
}

void onProviderEnabled (String provider) { 
  currentProvider = provider;
}

void onStatusChanged (String provider, int status, Bundle extras) {
  // Nothing yet...
}

}

But when I run this on my phone is gives me an error about the size() command. After filling the size I get "expecting EOF, found '}' "

Any help would be highly appreciated. Thanks in advance !

Tagged:

Answers

  • --- what version of P5 are you using??? --- size() with android mode is useless, it starts full screen --- what is "screenWidth"??? or "screenHeight???"

Sign In or Register to comment.