Location属性

 

int tempSpeed = (int) (location.getSpeed() * 3.6); // m/s --> Km/h

 

latitude.setText("N" + PositionUtil.ToLocation(gpsLocation.getLatitude()));//纬度
longitude.setText("E" + PositionUtil.ToLocation(gpsLocation.getLongitude()));//经度
altitude.setText("H:" + new DecimalFormat("#.00").format(gpsLocation.getAltitude()) + "m");//高程
currentTime.setText("");
accuracy.setText("精度:" + gpsLocation.getAccuracy() + "m");//精度
speed.setText("速度:" + gpsLocation.getSpeed() * 3.6 + "km/h");//速度 m/s --> km/h

经纬度转换成度分秒:

/**
 *
 * @note double location位置转换成 度分秒
 *
 * */
public static String ToLocation(double data){
    String ret_s = "";
    int tmp_i_du = (int)data;
    ret_s = String.valueOf(tmp_i_du)+"°";
    //度小数部分
    double tmp_d_du = data-tmp_i_du;
    int tmp_i_fen = (int)(tmp_d_du*60);
    ret_s = ret_s.concat(String.valueOf(tmp_i_fen)+"′");
    double tmp_d_fen = tmp_d_du*60 - tmp_i_fen;
    int tmp_i_miao = (int)(tmp_d_fen*60);
    ret_s = ret_s.concat(String.valueOf(tmp_i_miao)+"″");
    return ret_s;
}

/**
 *
 * @note double location位置转换成 度分秒
 * 以000°00′00.00″的形式
 * */
public static String dblToLocation(double data){
    String ret_s = "";
    int tmp_i_du = (int)data;
    ret_s = String.format("%03d",(int)tmp_i_du)+"°";
    //度小数部分
    double tmp_d_du = data-tmp_i_du;
    String tmp_i_fen = String.format("%02d",(int)(tmp_d_du*60));
    ret_s = ret_s.concat(tmp_i_fen+"′");
    double tmp_d_fen = tmp_d_du*60 - (int)(tmp_d_du*60);
    String tmp_i_miao = new DecimalFormat("00.00").format(tmp_d_fen*60);
    ret_s = ret_s.concat(tmp_i_miao+"″");
    return ret_s;
}

你可能感兴趣的:(Android基础,Android定位)