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
Contributor
Posts: 43
Registered: ‎11-24-2011
My Device: Perl
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

Developer
Posts: 144
Registered: ‎08-18-2012
My Device: Blackberry Curve 8520
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());
}
}
}

 

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

Re: How to get lat long using wifi