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
Developer
amiz
Posts: 34
Registered: ‎06-16-2009
My Device: Not Specified
Accepted Solution

getLocation issue

My app uses code from the GPS demo and am trying to acquire location using cellsites.

 

I am seeing two issues:

1. The code works on a 9550 simulator but does not return from a getLocation(-1) call on a Bold 9700 device

 

2. When in setupCriteria I use, the code hangs on that line.

 

Any pointers will be appreciated.

 

thanks

//myCriteria = new BlackBerryCriteria(GPSInfo.GPS_MODE_CELLSITE);

 

The code looks like this:

private void setupCriteria(){
	_criteria = new Criteria();
	_criteria.setHorizontalAccuracy(Criteria.NO_REQUIREMENT);
	_criteria.setVerticalAccuracy(Criteria.NO_REQUIREMENT);
	_criteria.setCostAllowed(true);
	_criteria.setPreferredPowerConsumption(Criteria.POWER_USAGE_LOW);
	//myCriteria = new BlackBerryCriteria(GPSInfo.GPS_MODE_CELLSITE);
}


private void createLocationProvider(){
	try {			
		_provider = LocationProvider.getInstance(myCriteria);
	} catch (LocationException e) {			
		status("Error in location acquisition");
	}
}	

private void getSingleFix(){		
	new Thread(){
		public void run(){
		       resetProvider();				
			setupCriteria();
			createLocationProvider();
			try {
			_location =_provider.getLocation(-1);	
} catch (LocationException e) { status("Error in location acquisition"); } catch (InterruptedException e) { status("Error in location acquisition"); } if(_location!=null && _location.isValid()){ QualifiedCoordinates coordinates = _location.getQualifiedCoordinates(); double lat = coordinates.getLatitude(); double longit = coordinates.getLongitude(); latlong(lat, longit); status(" "); log("In loc valid"); } else{ status("Error in location acquisition"); } } }.start(); } private void resetProvider(){ if(_provider!=null){ _provider.setLocationListener(null, 0, 0, 0); _provider.reset(); _provider=null; } } public void locationUpdated(LocationProvider provider, Location location) { if(location!=null && location.isValid()){ QualifiedCoordinates coordinates = location.getQualifiedCoordinates(); double lat = coordinates.getLatitude(); double longit = coordinates.getLongitude(); latlong(lat, longit); status(" "); } else{ status("Error in location acquisition"); } } public void providerStateChanged(LocationProvider provider, int newState) { /** * not implemented. For more information on how to implement this method please * refer to the BlackBerry Developer Knowledge Base Articles. */ }

 

 

 

Please use plain text.
Developer
NOTiFYPiNPOiNT
Posts: 55
Registered: ‎07-21-2009
My Device: Bold 9700 - 6.0 Bundle 1202 (v6.0.0.344, Platform 6.6.0.50)
My Carrier: Orange UK

Re: getLocation issue

Try setting Power Consumption to High and see if that works.

 

My GPS app appears to either hang or throw a null pointer exception when I try and use  Power Consumptin set to low on my BB 9700.

 

criteria.setPreferredPowerConsumption(

 

 

Criteria.POWER_USAGE_HIGH);

 

"It's all about quality (of posts) not quantity"
Please use plain text.
Developer
amiz
Posts: 34
Registered: ‎06-16-2009
My Device: Not Specified

Re: getLocation issue

Setting POWER_USAGE_HIGH made it work.

 

Thanks

 

 

 

Please use plain text.
Developer
amiz
Posts: 34
Registered: ‎06-16-2009
My Device: Not Specified

Re: getLocation issue

Testing the fix inside a building where there's no GPS, sometimes it works and other times it does not work.

 

Any ideas on how to make more consistent in acquiring a location using cell sites?

 

 

Please use plain text.
Developer
NOTiFYPiNPOiNT
Posts: 55
Registered: ‎07-21-2009
My Device: Bold 9700 - 6.0 Bundle 1202 (v6.0.0.344, Platform 6.6.0.50)
My Carrier: Orange UK

Re: getLocation issue

[ Edited ]

I use;

 

if (location != null && location.isValid()) {

 

To add the Latitude & Longitude to the string I send back to the server. If this data is null then when it is processed by my EJB on the server it uses the Cell ID & LAC code to get the Latitude & Longitude.

 

Ideally you (we) should be using;

 

public void providerStateChanged(final LocationProvider provider, final int newState) {

 

 

There is a bug and this method is never called, well at least not on the Bold 9700. It has been raised on the BB bug tracker.  See my post;

 

http://supportforums.blackberry.com/t5/Java-Development/locationProvider-getLocation-re-creating/m-p...

 

If this is effecting you perhaps you can vote for it to be fixed? The more the merrier!

"It's all about quality (of posts) not quantity"
Please use plain text.