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

Web and WebWorks Development

Reply
Contributor
Posts: 40
Registered: ‎04-27-2010
My Device: BOLD
My Carrier: INFORMATICO

get GPS coordenates

Hi, how can I get the GPS coordenates(lat,lon) ? some example?

 

thanks,

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

Re: get GPS coordenates

create a class and call this user defined method as

public void resetGPS()
{
 try {				
  criteria = new Criteria();
  criteria.setHorizontalAccuracy(500);
  criteria.setVerticalAccuracy(500);
  criteria.setCostAllowed(true);
  criteria.setPreferredPowerConsumption(Criteria.POWER_USAGE_LOW);
  provider = LocationProvider.getInstance(criteria);
  Location location =provider.getLocation(-1);
  if(provider!=null)
   {                
     provider.setLocationListener(new MyLocationListener(), 5, -1, -1);	
   }
} catch (Exception e) 
  {
   System.out.println("location exception"+e);
  }
}

 

create another class as : 

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) {}

 }
}

 

 

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: get GPS coordenates

The example above shows how to get GPS coordinates in Java.

 

For the web you have a couple of options.  One is the older blackberry.location object and the second is the Gears implementation.

 

The gears implementation requires OS 5.0

 

Example of the blackberry.location JavaScript can be found here:

http://www.blackberry.com/developers/docs/widgetapi/blackberry.location.html

 

Example of the Gears GeoLocation JavaScript can be found here:

http://www.blackberry.com/developers/docs/widgetapi/google.gears.geolocation.html

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter