Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
Developer
Posts: 282
Registered: ‎02-25-2010
My Device: curve,bold,storm
My Carrier: Verizon,AT&T
Accepted Solution

cannot find the gps location on the device

[ Edited ]

in my application i try to find the location of the user.my code owrks well in simulator for both curve8300 and bold 9000

 

but it does not fetches the cordinates on device even if i refresh the gps manually using options-->advanced options-->gps.

 

what to do

 package com.MyChamberApp;

    import javax.microedition.location.Criteria;
    import javax.microedition.location.Location;
    import javax.microedition.location.LocationListener;
    import javax.microedition.location.LocationProvider;

    public class GPS_Location {
     static double longi;
     static double lati;

     public GPS_Location() {

     }

     public void location()
     {
      new LocationTracker();
     }

     class LocationTracker 
     {
      private LocationProvider provider;
      Criteria cr;

      public LocationTracker() 
      {
       resetGPS();
      }

      public void resetGPS() {

      try {
      cr = new Criteria();
      cr.setPreferredPowerConsumption(Criteria.POWER_USAGE_HIGH);
      cr.setPreferredResponseTime(120000);
                cr.setCostAllowed(true);
      provider = LocationProvider.getInstance(cr);
      provider.getLocation(120);
      if (provider != null) 
       {
        provider.setLocationListener(new MyLocationListener(), 1,1,1);
       }
      } catch (Exception e) {}

      }

      public void run(){}

     private class MyLocationListener implements LocationListener 
         {
       public void providerStateChanged(LocationProvider provider,int newState)
       {
        if (newState == LocationProvider.TEMPORARILY_UNAVAILABLE)
        {
          provider.reset();
          resetGPS();
        }
       if (newState == LocationProvider.OUT_OF_SERVICE)
       {
        provider.reset();
        resetGPS();
       }
     }

     public void locationUpdated(LocationProvider provider,Location location) 
      {
       if (location != null && location.isValid()) {
        try {
      lati = location.getQualifiedCoordinates().getLatitude();
      longi = location.getQualifiedCoordinates().getLongitude();
         } catch (Exception e) {}
     }
      }
    }
   }
 }

 

 

Developer
Posts: 159
Registered: ‎08-19-2008
My Device: Not Specified

Re: cannot find the gps location on the device

Although code seems fine to me , check with this code.......................

 

 

Criteria criteria = new Criteria();

criteria.setHorizontalAccuracy(50);
            criteria.setVerticalAccuracy(50);
            criteria.setCostAllowed(true);
            criteria.setPreferredPowerConsumption(Criteria.POWER_USAGE_HIGH);
            _locationProvider = LocationProvider.getInstance(criteria);
              Location location =_locationProvider.getLocation(-1);
            _longitude = location.getQualifiedCoordinates().getLongitude();
            _latitude = location.getQualifiedCoordinates().getLatitude();
             _altitude = location.getQualifiedCoordinates().getAltitude();
             _speed = location.getSpeed();
            if(_locationProvider!=null)
             {                
              _locationProvider.setLocationListener(new LocationListenerImpl(), _interval, 1, 1);
              
            }

 

 

Developer
Posts: 282
Registered: ‎02-25-2010
My Device: curve,bold,storm
My Carrier: Verizon,AT&T

Re: cannot find the gps location on the device

Even this is also not working.What to do????????????????

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: cannot find the gps location on the device

[ Edited ]

What device are you trying this on, and what carrier and OS level?

 

Not all devices have GPS, not all carriers unlock autonomous GPS.

 

Also, you must be outside with a clear line of site to the satellites to get an autonomous fix.

 

Also, 120 seconds is probably not long enough for a first-fix. More like 180 seconds or higher.

 

Developer
Posts: 282
Registered: ‎02-25-2010
My Device: curve,bold,storm
My Carrier: Verizon,AT&T

Re: cannot find the gps location on the device

well i have worked on devices Like

curve 8330

bold 9000

 

os 4.5 and 4.6

 

i even tried with horizontal and vertical accuracy but no success

Developer
Posts: 159
Registered: ‎08-19-2008
My Device: Not Specified

Re: cannot find the gps location on the device

 

 

Check GPS Demo from samples in JDE , whether it is working on the device or not .................

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: cannot find the gps location on the device

It WORKED on these devices? or DID NOT WORK on these devices?

 

Please be specific and also tell us the OS level and carriers on the devices where it worked, and didn't work.

 

You might also want to review this KB article:

 

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800703/What_Is...

 

 

 

Developer
Posts: 282
Registered: ‎02-25-2010
My Device: curve,bold,storm
My Carrier: Verizon,AT&T

Re: cannot find the gps location on the device

well it did not worked on any device as i mentioned like curve and bold....

Developer
Posts: 159
Registered: ‎08-19-2008
My Device: Not Specified

Re: cannot find the gps location on the device

According to RexDoug & after searching in the forum , i found out that in some of devices autonomous GPS fix does not work , so check GPS Demo on the device if it is working on device then it means that there is a problem in your code otherwise autonomous GPS fix is not working on your devices................

Developer
Posts: 282
Registered: ‎02-25-2010
My Device: curve,bold,storm
My Carrier: Verizon,AT&T

Re: cannot find the gps location on the device

well i took reference from there only but let me try the exact same code on the device and find wats happening