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
Posts: 84
Registered: ‎07-22-2011
My Device: bb-9550,bb-9700
My Carrier: bb developer

To get the current location coordinates

Hi All

 

I need to get the current location coordinates on the start of the app.Iam working out in 8520 simulator.

Iam trying out with a sample code here but getting the location=null in 8520 simulator and in 9800 simulator iam getting the coordinates as 43.6775,-80. 7339

 

Criteria criteria = new Criteria();
        criteria.setVerticalAccuracy(50);
        criteria.setHorizontalAccuracy(50);
        criteria.setCostAllowed(true);
        criteria.setPreferredPowerConsumption(
        Criteria.POWER_USAGE_HIGH);
        try {
        screen.setMessage("Getting location...");
        LocationProvider provider =
        LocationProvider.getInstance(criteria);
        Location location = provider.getLocation(-1);
        QualifiedCoordinates qualifiedCoordinates =
        location.getQualifiedCoordinates();
        screen.setLocation(qualifiedCoordinates.getLongitude(),
        qualifiedCoordinates.getLatitude());

 

Plzzzz any help....

 

Thanks.

 
Highlighted
Developer
Posts: 151
Registered: ‎01-20-2010
My Device: Blackberry Bold
My Carrier: Telefonica

Re: To get the current location coordinates

are you sure that BB 8520 have GPS?

sorry for my english.

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

Re: To get the current location coordinates

Have a good look at this KB article and the code supplied is useful too:

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

Developer
Posts: 84
Registered: ‎07-22-2011
My Device: bb-9550,bb-9700
My Carrier: bb developer

Re: To get the current location coordinates

Hi peter,

 

I tried with this kb article also but iam unable to get the correct coordinates it is always showing 43.6775,-80.7339 but i need to get 17.492273,78.356008


plzzz help me out

 

Thanks

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

Re: To get the current location coordinates

If you look at the Simulator, in the 'Windows' menu you will see a Simulate menu option, click on that and you will see for most devices, a GPS option.  This is the location that it will get when using GPS.  I'm not sure how you can simulate any of the other location options, but if you change this I suspect it might change the others too. 

New Contributor
Posts: 9
Registered: ‎08-30-2012
My Device: BlackBerry 5.0
My Carrier: Airtel India

Re: To get the current location coordinates

You can use this code for getting current location ... Dont use this code directly. plz understand than use...

 

Class test

{

Criteria criteria;

LocationProvider locationProvider;

 

switch (MODE) {
case Constants.GPS_MODE_SATELLITE:  //1
criteria.setCostAllowed(false);
break;
case Constants.GPS_MODE_CELLSITE:   //2
criteria.setHorizontalAccuracy(Criteria.NO_REQUIREMENT);
criteria.setVerticalAccuracy(Criteria.NO_REQUIREMENT);
criteria.setCostAllowed(true);
criteria.setPreferredPowerConsumption(Criteria.POWER_USAGE_LOW);
// Will wait for two minutes
criteria.setPreferredResponseTime(120000);
break;
}

 

private LocationProvider getLocationProvider() throws LocationException {
return LocationProvider.getInstance(criteria);
}

 

 

}