Basic GPS App

I am currently working on the beginning stages of a GPS based Android app. It is very basic, essentially a map and compass are shown and direct you to the location, once you reach the location a sound is played. Currently the map works as well as the app being able to read and print the location of the device into the console. I can't seem to get the sound to play. And although the compass shows up on the screen it always points backwards/opposite of the location (I assume I need to change the point of the shape, but not sure where). If anyone sees where my code has went wrong I'd really appreciate your help.

`import ketai.sensors.*; import android.location.Location; import apwidgets.*;

KetaiLocation location; KetaiSensor sensor; Location Napier; PVector locationVector = new PVector(); float compass;

PImage img;

double longitude, latitude; float accuracy;

APMediaPlayer bing;

void setup() { Napier = new Location("Home"); Napier.setLatitude(55.9403355); Napier.setLongitude(-3.203854130);

location = new KetaiLocation(this); sensor = new KetaiSensor(this);

sensor.start();

bing = new APMediaPlayer(this); bing.setMediaFile("bing.mp3"); bing.setVolume(1.0, 1.0);

orientation(LANDSCAPE); textAlign(CENTER, CENTER); textSize(28); smooth(); }

void draw() { img = loadImage("NapierMap.jpg"); imageMode(CENTER); image(img, width/2, height/2, width, height); findNapier(); }

void findNapier() { float bearing = location.getLocation().bearingTo(Napier); float distance = location.getLocation().distanceTo(Napier); translate(width/2, height/2); rotate(radians(bearing) - radians(compass)); fill(#FF0000); triangle(-width/40, 0, width/40, 0, 0, -width/20); if (latitude => 55.9403350 && latitude =< 55.9403360 && longitude => -3.203854125 && longitude =< -3.203854135) { bing.start(); } }

void onLocationEvent(double _latitude, double _longitude, double _altitude, float _accuracy) {
longitude = _longitude; latitude = _latitude; accuracy = _accuracy; println("lat/lon/alt/acc: " + latitude + "/" + longitude + accuracy); }

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

void onOrientationEvent(float x, float y, float z, long time, int accuracy) { compass = x; } `

Tagged:

Comments

  • How to post code

    when you post your code:

    • in the editor hit ctrl-t to auto format

    • copy it

    • paste it in the browser

    • leave 2 empty lines before it, 1 line after it

    • mark the code (without the 3 empty lines)

    • press C in the small command bar.

  • edited February 2015
    import ketai.sensors.*;
    import android.location.Location;
    import apwidgets.*;
    
    KetaiLocation location;
    KetaiSensor sensor;
    Location Napier;
    PVector locationVector = new PVector();
    float compass;
    
    PImage img;
    
    double longitude, latitude;
    float accuracy;
    
    APMediaPlayer bing;
    
    void setup() {
      Napier = new Location("Home"); 
      Napier.setLatitude(55.9403355);
      Napier.setLongitude(-3.203854130);
    
      location = new KetaiLocation(this);
      sensor = new KetaiSensor(this);
    
      sensor.start();
    
      bing = new APMediaPlayer(this);
      bing.setMediaFile("bing.mp3");
      bing.setVolume(1.0, 1.0);
    
      orientation(LANDSCAPE);
      textAlign(CENTER, CENTER);
      textSize(28);
      smooth();
    }
    
    void draw() {
      img = loadImage("NapierMap.jpg");
      imageMode(CENTER);
      image(img, width/2, height/2, width, height);
      findNapier();
    }
    
    void findNapier() {
      float bearing = location.getLocation().bearingTo(Napier);
      float distance = location.getLocation().distanceTo(Napier);
      translate(width/2, height/2); 
      rotate(radians(bearing) - radians(compass)); 
      fill(#FF0000);
      triangle(-width/40, 0, width/40, 0, 0, -width/20);
      if (latitude => 55.9403350 && latitude =< 55.9403360 && longitude =>     -3.203854125 && longitude =< -3.203854135) {
        bing.start();
      }
    }
    
    void onLocationEvent(double _latitude, double _longitude, double _altitude, float _accuracy) {   
      longitude = _longitude;
      latitude = _latitude;
      accuracy = _accuracy;
      println("lat/lon/alt/acc: " + latitude + "/" + longitude + accuracy);
    }  
    
    void onLocationEvent(Location _location) {
      println("onLocation event: " + _location.toString());
      locationVector.x = (float)_location.getLatitude();  //(7)
      locationVector.y = (float)_location.getLongitude();
    }
    
    void onOrientationEvent(float x, float y, float z, long time, int accuracy) {
      compass = x;
    }
    

    Hope that's more legible.

  • @ stevieb====

    --- as for mediaplayer: a) your file must be in the data folder b) you have to change your code:: not AP... but:: PMediaPlayer bing;

    bing = new PMediaPlayer(this); ----bing.start();

    --- as for the rest i have tested, your triangle is false, try with a line, as or me it works; i can send you the corrected code if useful!

Sign In or Register to comment.