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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Contributor
maheshqtech
Posts: 41
Registered: ‎11-24-2011
My Carrier: BB
Accepted Solution

How to get lat long using wifi

I developed a web service and I want to get a lat long using wifi.

 

I using that lat long to pass it value to php side where I want to take a location my php code is ready

 

I want to get a lat long on blackberry

 

Can any one give the code for getting lat long suing wifi or GPRS.

 

Thanks In Advance

Please use plain text.
Developer
nikita18
Posts: 144
Registered: ‎08-18-2012
My Carrier: Vodafone

Re: How to get lat long using wifi

Try this code:

 

public class LocHandler extends Thread{

private BlackBerryCriteria blackBerryCriteria = null;
private BlackBerryLocation blackBerryLocation = null;
private BlackBerryLocationProvider blackBerryLocationProvider = null;
double lat = 0.0;
double lng = 0.0;

public void run(){
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
{
blackBerryCriteria.setCostAllowed(true);
blackBerryCriteria.setPreferredPowerConsumption(Criteria.POWER_USAGE_LOW);
}

try {
blackBerryLocationProvider = (BlackBerryLocationProvider) BlackBerryLocationProvider.getInstance(blackBerryCriteria);
blackBerryLocation = (BlackBerryLocation) blackBerryLocationProvider.getLocation(60);

QualifiedCoordinates qualifiedCoordinates = blackBerryLocation.getQualifiedCoordinates();

lat = qualifiedCoordinates.getLatitude();
lng = qualifiedCoordinates.getLongitude();

System.out.println("Latitude :"+lat);
System.out.println("Longitude :"+lng);
}
catch(Exception e)
{
System.out.println("Error in location :"+e.toString());
System.out.println("Error in location :"+e.getMessage());
}
}
}

 

Please use plain text.
Developer
peter_strange
Posts: 17,634
Registered: ‎07-14-2008

Re: How to get lat long using wifi

Please use plain text.