×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    13

    Unhappy Location Api error

    Hi everyone,

    I'm developing gps application.This application find the users's gps coordinate.But i cant get the points because LocationProvider.getInstance get null.My code is below;

    public class GpsLocation
    extends Thread
    {
    private double lat; //lattitude
    private double lon; //longtitude
    private boolean gpsSupport; //gps destekleniyormu

    /** Selected criteria */
    private Criteria criteria = null;

    /** Selected location provider */
    private LocationProvider provider = null;

    /**
    *Constructor
    */
    public GpsLocation()
    {
    //default values
    lat=0;
    lon=0;
    gpsSupport=false;
    //Detect Gps support or not support
    if(isLocationApiSupported())
    gpsSupport=true;
    else
    gpsSupport=false;
    }

    public void run()
    {
    if(gpsSupport)
    checkLocation();
    else
    AnaMidlet.popUpUyariGoster("GPS desteklenmiyor");
    }

    public void checkLocation()
    {
    try
    {
    Criteria cr = new Criteria();
    //cr.setHorizontalAccuracy(500);
    cr.setPreferredPowerConsumption(Criteria.POWER_USAGE_HIGH);
    provider = null;

    provider = LocationProvider.getInstance(criteria);
    if (provider != null)
    {
    Location lc=LocationProvider.getLastKnownLocation();
    if(lc!=null && lc.isValid()){
    QualifiedCoordinates coordinates=lc.getQualifiedCoordinates();
    // Location provider found, send a selection event.
    if (coordinates != null) {
    // Get the latitude and longitude of the coordinates.
    lat = coordinates.getLatitude();
    lon = coordinates.getLongitude();
    AnaMidlet.popUpUyariGoster("Lattitude:"+getLat()+ "Longtitude:"+getLon());
    }
    else {
    AnaMidlet.popUpUyariGoster("Coordinates Null");
    }
    }
    else{
    AnaMidlet.popUpUyariGoster("Location Null");
    }
    }
    else
    {
    AnaMidlet.popUpUyariGoster("Location Provider Null");
    }
    }
    catch(Exception e){
    AnaMidlet.popUpUyariGoster("GPS EXCEPTION:"+e.getMessage());
    }
    }



    provider = LocationProvider.getInstance(criteria); this line get null during the application run on my mobile N79..ı know n79 has gps system..My platform is j2me polish and i use eclipse 3.4 ganymede and Sun Wtk 2.5.2..for Any solutions and advice thanks..Kamo

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

    Re: Location Api error

    Code:
    Criteria cr = new Criteria();
    //cr.setHorizontalAccuracy(500);
    cr.setPreferredPowerConsumption(Criteria.POWER_USAGE_HIGH);
    provider = null;
    
    provider = LocationProvider.getInstance(criteria);
    Well you are instantiating a Criteria variable called cr and afterwards you try to pass a variable to LocationProvider.getInstance() called criteria... spot the difference

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    13

    Re: Location Api error

    Thanks for reply tiger.I see the wrong but i changed criteria object with class variable and the result is same.null

    last code for gps class

    /**
    * Kamo@Columbus
    */
    package net.columbus.polish;
    import javax.microedition.location.*;

    /**
    * @author kamo
    * GpsLocation Class
    */


    public class GpsLocation
    {
    private double lat; //lattitude
    private double lon; //longtitude

    /** Selected criteria */
    private Criteria criteria;;

    /** Selected location provider */
    private LocationProvider provider;

    /**
    *Constructor
    */
    public GpsLocation()
    {
    //default values
    lat=0;
    lon=0;
    this.provider=null;
    this.criteria=null;
    //Gps destekleniyormu burada anlasiliyor true destekleniyor else yok
    if(isLocationApiSupported()){
    checkLocation();
    }
    else{
    AnaMidlet.popUpUyariGoster("GPS desteklenmiyor");
    }
    }

    public void checkLocation()
    {
    try
    {
    criteria = new Criteria();
    criteria.setAddressInfoRequired(false);
    criteria.setAltitudeRequired(false);
    criteria.setHorizontalAccuracy(500); // 500m
    criteria.setVerticalAccuracy(500); // 500m
    criteria.setPreferredPowerConsumption(Criteria.POWER_USAGE_LOW);
    criteria.setSpeedAndCourseRequired(false);
    criteria.setPreferredResponseTime(Criteria.NO_REQUIREMENT);

    provider = LocationProvider.getInstance(criteria);
    if (provider != null)
    {
    Location lc=LocationProvider.getLastKnownLocation();
    if(lc!=null && lc.isValid()){
    QualifiedCoordinates coordinates=lc.getQualifiedCoordinates();
    // Location provider found, send a selection event.
    if (coordinates != null) {
    // Get the latitude and longitude of the coordinates.
    lat = coordinates.getLatitude();
    lon = coordinates.getLongitude();
    AnaMidlet.popUpUyariGoster("Lattitude:"+lat+ "Longtitude:"+lon);
    }
    else {
    AnaMidlet.popUpUyariGoster("Coordinates Null");
    }
    }
    else{
    AnaMidlet.popUpUyariGoster("Location Null");
    }
    }
    else
    {
    AnaMidlet.popUpUyariGoster("Location Provider Null");
    }
    }
    catch(Exception e){
    AnaMidlet.popUpUyariGoster("GPS EXCEPTION:"+e.getMessage());
    }
    }

    /**
    * Checks whether Location API is supported.
    *
    * @return a boolean indicating is Location API supported.
    */
    public boolean isLocationApiSupported()
    {
    String version = System.getProperty("microedition.location.version");
    return (version != null && !version.equals("")) ? true : false;
    }

    /**
    * @return the lat
    */
    public double getLat() {
    return lat;
    }

    /**
    * @param lat the lat to set
    */
    public void setLat(double lat) {
    this.lat = lat;
    }

    /**
    * @return the lon
    */
    public double getLon() {
    return lon;
    }

    /**
    * @param lon the lon to set
    */
    public void setLon(double lon) {
    this.lon = lon;
    }
    }

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

    Re: Location Api error

    Have you checked the Wiki article :
    http://wiki.forum.nokia.com/index.ph...aining_GPS_fix

    try to keep the Criteria as simple as possible, also you are trying to get the lastKnownLocation (LocationProvider.getLastKnownLocation() and I don't know what te result would be if there is no previous known location...
    Just read the wiki, implement the LocationListener interface...
    You can also try to debug through the Emulator and see when and where you get the exception...

  5. #5
    Registered User
    Join Date
    Sep 2009
    Posts
    13

    Re: Location Api error

    Thanks i'll read and try..

Similar Threads

  1. XMl Parser Implementation for Symbian
    By ittiam in forum Symbian
    Replies: 26
    Last Post: 2009-09-16, 05:26
  2. [newbie here] Link error
    By xitpu in forum Symbian
    Replies: 3
    Last Post: 2007-01-24, 16:53
  3. S80 Platform SDK and Visual Studio .NET Linking Error
    By jayantjain in forum Mobile Java Tools & SDKs
    Replies: 1
    Last Post: 2005-10-07, 22:14
  4. how to avoid linking error
    By skdas in forum Symbian
    Replies: 6
    Last Post: 2003-07-07, 07:57

Posting Permissions

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