I want to get longitude
and latitude
of the phone mobile by this code:
public void commandAction(Command com, Displayable d) {
if (com == position)
{
try
{
Criteria cr = new Criteria();
cr.setHorizontalAccuracy(500);
LocationProvider lp = LocationProvider.getInstance(cr);
// get the location, one minute timeout
Location l = lp.getLocation(60);
Coordinates coords = l.getQualifiedCoordinates();
if (coords != null)
{
double longitude = coords.getLongitude();
double latitude = coords.getLatitude();
String sLong = String.valueOf(longitude);
String sLat = String.valueOf(latitude);
Tlongitude.setString(sLong);
Tlatitude.setString(sLat);
}
} catch (LocationException ex) {
Tlongitude.setString("LocationException");
Tlatitude.setString("LocationException");
} catch (InterruptedException ex) {
Tlongitude.setString("InterruptedException");
Tlatitude.setString("InterruptedException");
}
}
}
The problem is that when clicking the "position" command then a system alert is shown saying : java.lang.SecurityException : Application not authorized to access the restricted API
.
So what should I do?