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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Trusted Contributor
Posts: 109
Registered: ‎11-15-2011
My Device: blackberry 9800
My Carrier: beginner developer

unable to get latitude and longitude of current location

Hi,

I want to have the GPS location of current location.

I used this method . But I cann't use it only outside and it didn't worked in office and it  it dipslay time out while waiting for GPS loaction. There are another method to get current location??

public class LocationScreen extends MainScreen 
{
      public LocationScreen() 
      {
        super();
        final LabelField lfLocation = new LabelField();
        new Thread()
        {
          public void run() 
          {
            LocationHandler lh = new LocationHandler();
            final String msg = "Long: " + lh.getCurrentLongitude() + ", Lat: " + lh.getCurrentLatitude();

            Application.getApplication().invokeLater(new Runnable() 
            {
              public void run() 
              {
                lfLocation.setText(msg);
                add(new LabelField("Lat and Long=="+msg));
              }
            });
          }
        }.start();
        this.add(lfLocation);
      }
    }

**Second Class**

public class LocationHandler 
{
  private LocationProvider locationProvider;
  private Location currentLocation;
  public LocationHandler()  
  {
    try 
    {
      locationProvider = LocationProvider.getInstance(null);
      currentLocation = locationProvider.getLocation(60);
    }
    catch (final Exception e) 
    {
      Application.getApplication().invokeLater(new Runnable() 
      {
        public void run() 
        {
          Status.show(e.getMessage());
        }
      });
    }
  }
  public double getCurrentLongitude() 
  {
    if(currentLocation != null)
      return currentLocation.getQualifiedCoordinates().getLongitude();
    return -1;
  }
  public double getCurrentLatitude() 
  {
    if(currentLocation != null)
      return currentLocation.getQualifiedCoordinates().getLatitude();
    return -1;
  }

 

Developer
Posts: 36
Registered: ‎06-28-2012
My Device: BB10
My Carrier: RIM

Re: unable to get latitude and longitude of current location

Hi,

 

Check out this link : 

http://supportforums.blackberry.com/t5/Java-Development/Location-APIs-Start-to-finish/ta-p/571949

 

Also you can check the sample demo named GPSDemoAdvance available.

 

Thanks

Trusted Contributor
Posts: 109
Registered: ‎11-15-2011
My Device: blackberry 9800
My Carrier: beginner developer

Re: unable to get latitude and longitude of current location

It's not clear. There are many things in this link. What's method should I add to use GPS when the user is at home or office

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: unable to get latitude and longitude of current location

I agree, it is not clear.  And it is not simple because different methods work with different networks.  And if you have different OS levels you can do different things.

 

Unfortunately however in the real world of BlackBerry, we have all these options to consider and contend with.  So you will need to do some research and decide the best approach for yourself.  The Article you have been pointed out is a great start. 

 

I recommend that you review this code too:

http://supportforums.blackberry.com/t5/Java-Development/Simple-Location-API/ta-p/1145951

 

For me, for people who are inside a lot, carrier or BB Cell Site location are the best approach.  Also free and fast.  But not very accurate.....

Developer
Posts: 255
Registered: ‎05-03-2012
My Device: 9930
My Carrier: Vodafone

Re: unable to get latitude and longitude of current location

[ Edited ]
Try this :
BlackBerryCriteria blackBerryCriteria = new BlackBerryCriteria(); if(GPSInfo.isGPSModeAvailable(GPSInfo.GPS_MODE_CELLSITE)) { blackBerryCriteria.setMode(GPSInfo.GPS_MODE_CELLSITE); } else if(GPSInfo.isGPSModeAvailable(GPSInfo.GPS_MODE_ASSIST)) { blackBerryCriteria.setMode(GPSInfo.GPS_MODE_ASSIST); } else if(GPSInfo.isGPSModeAvailable(GPSInfo.GPS_MODE_AUTONOMOUS)) { blackBerryCriteria.setMode(GPSInfo.GPS_MODE_AUTONOMOUS); } else if(GPSInfo.isGPSModeAvailable(GPSInfo.GPS_MODE_CDMA_SPEED_OPTIMAL)) { blackBerryCriteria.setMode(GPSInfo.GPS_MODE_CDMA_SPEED_OPTIMAL); } else { blackBerryCriteria.setCostAllowed(false); blackBerryCriteria.setPreferredPowerConsumption(BlackBerryCriteria.POWER_USAGE_LOW); } try { BlackBerryLocationProvider blackBerryLocationProvider = (BlackBerryLocationProvider) BlackBerryLocationProvider.getInstance(blackBerryCriteria); Location blackBerryLocation = (Location) blackBerryLocationProvider.getLocation(30); QualifiedCoordinates qualifiedCoordinates = blackBerryLocation.getQualifiedCoordinates(); lat = qualifiedCoordinates.getLatitude(); lng = qualifiedCoordinates.getLongitude(); } catch(Exception e) { }

 

Trusted Contributor
Posts: 109
Registered: ‎11-15-2011
My Device: blackberry 9800
My Carrier: beginner developer

Re: unable to get latitude and longitude of current location

Hi JoVinz, 

I tried this example and I get an exception that getLocation() method cannot be called from event thread.

I made

 class A extends Thread
{
code
}

 and called in the other class

Thread t = new A();
t.run();

 Can you help what is the problem

 

Developer
Posts: 255
Registered: ‎05-03-2012
My Device: 9930
My Carrier: Vodafone

Re: unable to get latitude and longitude of current location

I didnt use a class that extends thread. I simply created a thread.
and started like this:

UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
t.start();
}
});

 In your case you are blocking event thread. use UiApplication.getUiApplication.invokeLater to solve this issue.