×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    13

    Location API Problem

    Hi all,
    I got code from this forum and tried to run on N95 for getting Altitude,Lat and long.But i am getting TimeOutException.
    Can anyone suggest how to run it successfully i also used the LocationListener interface.
    I have also included permisions.for location.below is my code
    ******************************************************************
    package hello;

    import java.io.*;
    import java.util.*;

    import javax.microedition.io.*;
    import javax.microedition.midlet.*;

    import javax.microedition.lcdui.*;
    import javax.microedition.location.*;

    public class GPS extends MIDlet implements CommandListener,LocationListener{

    Command Exit = new Command("Exit",Command.EXIT,0);
    Form f = new Form("wait");
    public GPS() {}

    public void startApp() {

    f.append("geting gps data.");
    f.addCommand(Exit);
    f.setCommandListener(this);
    Display.getDisplay(this).setCurrent(f);
    try {
    Criteria c=new Criteria();
    c.setHorizontalAccuracy(1000);
    c.setVerticalAccuracy(1000);

    c.setPreferredPowerConsumption(Criteria.POWER_USAGE_HIGH);

    LocationProvider lp=LocationProvider.getInstance(c);
    Location loc=lp.getLocation(60);

    /*QualifiedCoordinates qc=loc.getQualifiedCoordinates();
    f.append("Alt: "+qc.getAltitude());
    f.append("Lat: "+qc.getLatitude());
    f.append("Long: "+qc.getLongitude());*/

    } catch(Exception e) {
    f.append("Exception: "+e);
    }

    }





    public void pauseApp() {}

    public void destroyApp(boolean destroy) {}

    public void commandAction(Command c, Displayable s) {
    if (c == Exit) {
    destroyApp(true);
    notifyDestroyed();
    }
    }

    public void locationUpdated(LocationProvider lp, Location loc) {
    f.append("Location Updated");
    f.append("Location Method"+loc.getLocationMethod());
    f.append("Speed:"+loc.getSpeed());
    f.append("valid:"+loc.isValid());
    f.append("Location"+lp.toString());
    }

    public void providerStateChanged(LocationProvider lp, int arg1) {
    f.append("Location State Changed:");

    }
    }
    ******************************************************************

    Thanks and Regards,
    Sandeep Gadhvi

  2. #2
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Location API Problem

    actually u might want to look throught the documentation of the API itself...
    there u might discover something regarding a setLocationListener method
    that should help u a lot

    it's very handy to learn the tools u are working with so that u wont be completely dependant on someone elses code and/or help...

Similar Threads

  1. Location API
    By davidlt27 in forum Mobile Java Networking & Messaging & Security
    Replies: 3
    Last Post: 2008-06-23, 15:49
  2. N95 + Location API + V20 Firmware = no-go ?
    By Tiger79 in forum Mobile Java General
    Replies: 0
    Last Post: 2008-03-05, 12:13
  3. How to obtain Location API
    By Tiger79 in forum Mobile Java Tools & SDKs
    Replies: 1
    Last Post: 2007-04-27, 05:37
  4. PIM API adding new contacts problem
    By hoppelmoppel in forum Mobile Java General
    Replies: 3
    Last Post: 2007-04-22, 17:12
  5. Location API security limitations?
    By jkirma in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2006-05-29, 06:10

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×