我想通过以下代码获取手机longitude
的latitude
手机:
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");
}
}
}
问题是,当单击“位置”命令时,会显示系统警报:java.lang.SecurityException : Application not authorized to access the restricted API
。
所以我该怎么做?