onLocationEvent() seems that this method is never called

edited September 2014 in Android Mode

Hi, I copy/pasted this code from the book Rapid Android Development, but it seems that the onLocationEvent method is never called/happening. I just added a counter, to see if it fires. The onOrientationEvent fires a few times per second.

Here's the code:

import ketai.sensors.*;
import android.location.Location;
KetaiLocation location;
KetaiSensor sensor;
Location destination;
PVector locationVector = new PVector();
float compass;
int locEvent=0, compEvent=0;


void setup() {
  destination = new Location("Hrenova ulica 11");
  destination.setLatitude(45.959448);
  destination.setLongitude(-14.528655);
  location = new KetaiLocation(this);
  sensor = new KetaiSensor(this);
  sensor.start();
  orientation(PORTRAIT);
  textAlign(CENTER, CENTER);
  textSize(28);
  smooth();
}

void draw() {
  background(78, 93, 75);
  float bearing = location.getLocation().bearingTo(destination);
  float distance = location.getLocation().distanceTo(destination);
  if (mousePressed) {
    if (location.getProvider() == "none")
      text("Location data is unavailable. \n" +
        "Please check your location settings.", 0, 0, width, height);
    else
      text("Location:\n" +
      "locEvent: " + locEvent + "\n" + 
      "compEvent: " + compEvent + "\n" + 
      "Latitude: " + locationVector.x + "\n" +
      "Longitude: " + locationVector.y + "\n" +
      "Compass: "+ round(compass) + " deg.\n" +
      "Destination:\n" +
      "Bearing: " + bearing + "\n" +
      "Distance: "+ distance + " m\n" +
      "Provider: " + location.getProvider(), 20, 0, width, height);
  } else {
    translate(width/2, height/2);
    rotate(radians(bearing) - radians(compass));
    stroke(255);
    triangle(-width/4, 0, width/4, 0, 0, -width/2);
    text((int)distance + " m", 0, 50);
    text(nf(distance*0.000621, 0, 2) + " miles", 0, 100);
  }
}

void onLocationEvent(Location _location)
{
  println("onLocation event: " + _location.toString());
  locationVector.x = (float)_location.getLatitude();
  locationVector.y = (float)_location.getLongitude();
  locEvent++;
}

void onOrientationEvent(float x, float y, float z, long time, int accuracy)
{
  compass = x;
  compEvent++;
  // Azimuth angle between the magnetic north and device y-axis, around z-axis.
  // Range: 0 to 359 degrees
  // 0=North, 90=East, 180=South, 270=West
}

So, if any one sees what's wrong, please let me know :)

Regards.

Tagged:
Sign In or Register to comment.